Commit Graph

61 Commits

Author SHA1 Message Date
Mike Bayer 2db54ee92e Leave bytestring exception messages as bytestrings
Fixed a regression introduced in version 1.2 where a refactor
of the :class:`.SQLAlchemyError` base exception class introduced an
inappropriate coercion of a plain string message into Unicode under
python 2k, which is not handled by the Python interpreter for characters
outside of the platform's encoding (typically ascii).  The
:class:`.SQLAlchemyError` class now passes a bytestring through under
Py2K for ``__str__()`` as is the behavior of exception objects in general
under Py2K, does a safe coercion to unicode utf-8 with
backslash fallback for ``__unicode__()``.  For Py3K the message is
typically unicode already, but if not is again safe-coerced with utf-8
with backslash fallback for the ``__str__()`` method.

Fixes: #4429
Change-Id: I2289da3f2c45c7d0041fa43d838958f7614defc3
2019-01-10 18:02:00 -05:00
Mike Bayer 1e278de4cc Post black reformatting
Applied on top of a pure run of black -l 79 in
I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9,  this set of changes
resolves all remaining flake8 conditions for those codes
we have enabled in setup.cfg.

Included are resolutions for all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.

Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
2019-01-06 18:23:11 -05:00
Mike Bayer 1e1a38e780 Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits
applied at all.

The black run will format code consistently, however in
some cases that are prevalent in SQLAlchemy code it produces
too-long lines.   The too-long lines will be resolved in the
following commit that will resolve all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.

Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
2019-01-06 17:34:50 +00:00
Mike Bayer 0b0a4c8ba2 Handle PostgreSQL enums in remote schemas
Fixed issue where a :class:`.postgresql.ENUM` or a custom domain present
in a remote schema would not be recognized within column reflection if
the name of the enum/domain or the name of the schema required quoting.
A new parsing scheme now fully parses out quoted or non-quoted tokens
including support for SQL-escaped quotes.

Fixed issue where multiple :class:`.postgresql.ENUM` objects referred to
by the same :class:`.MetaData` object would fail to be created if
multiple objects had the same name under different schema names.  The
internal memoization the Postgresql dialect uses to track if it has
created a particular :class:`.postgresql.ENUM` in the database during
a DDL creation sequence now takes schema name into account.

Fixes: #4416
Change-Id: I8cf03069e10b12f409e9b6796e24fc5850979955
2018-12-21 13:53:16 -05:00
Korn, Uwe 85dd766853 Mention Properties keys in __dir__
The Python builtin ``dir()`` is now supported for a SQLAlchemy "properties"
object, such as that of a Core columns collection (e.g. ``.c``),
``mapper.attrs``, etc.  Allows iPython autocompletion to work as well.
Pull request courtesy Uwe Korn.

Change-Id: I8696729542d1b74a566642a3a63fd500f64588cd
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/458

Mention Properties keys in __dir__

Change-Id: I88939955857c8df5eed0b87bc27c45357780b17d
2018-08-01 12:30:57 -04:00
Mike Bayer 1a990ee332 Ensure Oracle index w/ col DESC etc. is reflected
Fixed bug where an index reflected under Oracle with an expression like
"column DESC" would not be returned, if the table also had no primary
key, as a result of logic that attempts to filter out the
index implicitly added by Oracle onto the primary key columns.

Reworked the "filter out the primary key index" logic in oracle
get_indexes() to be clearer.

This changeset also adds an internal check to ColumnCollection
to accomodate for the case of a column being added twice,
as well as adding a private _table argument to Index such that
reflection can specify the Table explicitly.  The _table
argument can become part of public API in a later revision
or release if needed.

Change-Id: I745711e03b3e450b7f31185fc70e10d3823063fa
Fixes: #4042
2017-08-14 01:18:06 -04:00
Khairi Hafsham 772374735d Make all tests to be PEP8 compliant
tested using pycodestyle version 2.2.0

Fixes: #3885
Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
2017-02-07 11:21:56 -05:00
Mike Bayer 665b92d83f Check for __module__ not present in util.wrap_callable()
The newly added wrap_callable() function assumes __module__
is present when this is not the case for objects such as
functools.partial.

Change-Id: Ia226260e9a65419e26d5c1f7187512f7fd4bb7c1
Fixes: #3823
2016-10-14 13:26:35 -04:00
Pieter Mulder fcfff77128 Repair pickling for Properties object
Fixed bug whereby the ``__getstate__`` / ``__setstate__``
methods for sqlalchemy.util.Properties were
non-working due to the transition in the 1.0 series to ``__slots__``.
The issue potentially impacted some third-party applications.
Pull request courtesy Pieter Mulder.

Fixes: #3728
Change-Id: I01ebd425bbfe145747fea2edd0d2d412c74fd84d
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/286
(cherry picked from commit cab57e9bab04fbdea44690c08dff379a29eaab32)
2016-06-29 17:21:31 -04:00
Mike Bayer 01809bddff - Fixed bug in "to_list" conversion where a single bytes object
would be turned into a list of individual characters.  This would
impact among other things using the :meth:`.Query.get` method
on a primary key that's a bytes object.
fixes #3660
2016-02-21 20:52:43 -05:00
Mike Bayer 8a1e619fb2 - revert the change first made in a6fe4dc, as we are now generalizing
the warning here to all safe_reraise() cases in Python 2.
- Revisiting 🎫`2696`, first released in 1.0.10, which attempts to
work around Python 2's lack of exception context reporting by emitting
a warning for an exception that was interrupted by a second exception
when attempting to roll back the already-failed transaction; this
issue continues to occur for MySQL backends in conjunction with a
savepoint that gets unexpectedly lost, which then causes a
"no such savepoint" error when the rollback is attempted, obscuring
what the original condition was.

The approach has been generalized to the Core "safe
reraise" function which takes place across the ORM and Core in any
place that a transaction is being rolled back in response to an error
which occurred trying to commit, including the context managers
provided by :class:`.Session` and :class:`.Connection`, and taking
place for operations such as a failure on "RELEASE SAVEPOINT".
Previously, the fix was only in place for a specific path within
the ORM flush/commit process; it now takes place for all transational
context managers as well.
fixes #2696
2016-01-28 15:01:31 -05:00
Mike Bayer d4d9a65248 - Fixed bug where some exception re-raise scenarios would attach
the exception to itself as the "cause"; while the Python 3 interpreter
is OK with this, it could cause endless loops in iPython.
fixes #3625
- add tests for reraise, raise_from_cause
- raise_from_cause is the same on py2k/3k, use just one function
2016-01-18 17:35:44 -05:00
Iuri de Silvio d9178320d6 Fix _assert_unorderable_types on py36.
The error message changed to:

`'<' not supported between instances of 'foo' and 'bar'`
2015-11-30 14:50:25 -02:00
Mike Bayer e31211c578 - convert wrap_callable() to a general purpose update_wrapper-like
function; the caller still passes in the "wrapper"
- move tests for wrap_callable() to be generic util tests
- changelog for pullreq github:204
2015-10-29 14:28:00 -04:00
Mike Bayer 575f080850 - Fixed an issue where a particular base class within utils
didn't implement ``__slots__``, and therefore meant all subclasses
of that class didn't either, negating the rationale for ``__slots__``
to be in use.  Didn't cause any issue except on IronPython
which apparently does not implement ``__slots__`` behavior compatibly
with cPython.
Fixes #3494
2015-07-20 20:35:04 -04:00
Mike Bayer 657be357de - Fixed an internal "memoization" routine for method types such
that a Python descriptor is no longer used; repairs inspectability
of these methods including support for Sphinx documentation.
2015-06-08 18:36:27 -04:00
Mike Bayer de11f94982 - The :meth:.PropComparator.of_type modifier has been
improved in conjunction with loader directives such as
:func:`.joinedload` and :func:`.contains_eager` such that if
two :meth:`.PropComparator.of_type` modifiers of the same
base type/path are encountered, they will be joined together
into a single "polymorphic" entity, rather than replacing
the entity of type A with the one of type B.  E.g.
a joinedload of ``A.b.of_type(BSub1)->BSub1.c`` combined with
joinedload of ``A.b.of_type(BSub2)->BSub2.c`` will create a
single joinedload of ``A.b.of_type((BSub1, BSub2)) -> BSub1.c, BSub2.c``,
without the need for the ``with_polymorphic`` to be explicit
in the query.
fixes #3256
2014-11-24 18:49:32 -05:00
Mike Bayer fb09ad7551 - The `__module__` attribute is now set for all those SQL and
ORM functions that are derived as "public factory" symbols, which
should assist with documentation tools being able to report on the
target module.
fixes #3218
2014-10-14 11:59:48 -04:00
Mike Bayer 685a014c64 - A new implementation for :class:.KeyedTuple used by the
:class:`.Query` object offers dramatic speed improvements when
fetching large numbers of column-oriented rows.
fixes #3176
2014-08-28 12:25:21 -04:00
Mike Bayer c9843bb395 put fails for these various things that don't work on pypy, not sure what approach
should be taken
2014-03-08 13:52:27 -05:00
Mike Bayer 66470d8656 fix pypy failures 2014-03-03 16:18:09 -05:00
Mike Bayer bf89ca2e10 - get util.get_callable_argspec() to be completely bulletproof for 2.6-3.4,
methods, classes, builtins, functools.partial(), everything known so far
- use get_callable_argspec() within ColumnDefault._maybe_wrap_callable, re: #2979
2014-03-02 13:59:06 -05:00
Mike Bayer c2f86c92b1 restore the contracts of update/extend to the degree that the same column identity
isn't appended to the list.  reflection makes use of this.
2014-02-27 13:50:47 -05:00
Mike Bayer 302ad6228a - Some changes to how the :attr:.FromClause.c collection behaves
when presented with duplicate columns.  The behavior of emitting a
warning and replacing the old column with the same name still
remains to some degree; the replacement in particular is to maintain
backwards compatibility.  However, the replaced column still remains
associated with the ``c`` collection now in a collection ``._all_columns``,
which is used by constructs such as aliases and unions, to deal with
the set of columns in ``c`` more towards what is actually in the
list of columns rather than the unique set of key names.  This helps
with situations where SELECT statements with same-named columns
are used in unions and such, so that the union can match the columns
up positionally and also there's some chance of :meth:`.FromClause.corresponding_column`
still being usable here (it can now return a column that is only
in selectable.c._all_columns and not otherwise named).
The new collection is underscored as we still need to decide where this
list might end up.   Theoretically it
would become the result of iter(selectable.c), however this would mean
that the length of the iteration would no longer match the length of
keys(), and that behavior needs to be checked out.
fixes #2974
- add a bunch more tests for ColumnCollection
2014-02-26 15:34:49 -05:00
Mike Bayer c450cd6cb6 - Fixed regression where using a `functools.partial()` with the event
system would cause a recursion overflow due to usage of inspect.getargspec()
on it in order to detect a legacy calling signature for certain events,
and apparently there's no way to do this with a partial object.  Instead
we skip the legacy check and assume the modern style; the check itself
now only occurs for the SessionEvents.after_bulk_update and
SessionEvents.after_bulk_delete events.  Those two events will require
the new signature style if assigned to a "partial" event listener.
[ticket:2905]
2014-01-04 00:35:48 -05:00
Mike Bayer 2692238f45 - Improvements to the system by which SQL types generate within
``__repr__()``, particularly with regards to the MySQL integer/numeric/
character types which feature a wide variety of keyword arguments.
The ``__repr__()`` is important for use with Alembic autogenerate
for when Python code is rendered in a migration script.
[ticket:2893]
2013-12-18 18:26:15 -05:00
Mike Bayer 9769628ac1 - add WeakSequence.append()
- fix and test weakref cleanout for WeakSequence, [ticket:2794]
2013-08-18 16:05:38 -04:00
Mike Bayer 0d9ec9fe84 remove all remaining start/end py2k/py3k blocks 2013-06-07 17:51:12 -04:00
Mike Bayer 6e99c0b04e merge default 2013-05-23 13:02:33 -04:00
Mike Bayer 2eaae08f48 Fixed a bug where the routine to detect the correct kwargs
being sent to :func:`.create_engine` would fail in some cases,
such as with the Sybase dialect.
[ticket:2732]
2013-05-23 12:59:53 -04:00
Mike Bayer 8be6831f8b base 2013-05-04 16:00:05 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Diana Clarke 40071dbda4 initializing _labels to an empty list so that the other methods don't throw exceptions in the None labels case, but rather return (), [], or {}. this is not backwards compatible, but doubt anyone is relying on those exceptions #2601 2012-11-17 15:28:50 -05:00
Diana Clarke dbdd0fdd48 adding _fields, _asdict() to KeyedTuple #2601 2012-11-17 14:55:26 -05:00
Diana Clarke e469529a1d adding tests for KeyedTuple, pep8 pass 2012-11-17 09:51:12 -05:00
Diana Clarke 8a4ab8a4db oops! python 3 doesn't do the rich comparison cmp thing 2012-11-14 23:25:09 -05:00
Diana Clarke f0e19297ee __sub__ was declared twice, just increasing test coverage before I change anything 2012-11-13 18:51:35 -05:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 22ba1c43b7 -whitespace bonanza, contd 2012-07-28 17:05:50 -04:00
Mike Bayer c5f8241006 remove WeakIdentityMapping tests 2012-06-24 02:29:08 -04:00
Mike Bayer ff0fb31bf2 - merge attribute flag overhaul for [ticket:2358] 2012-04-23 11:45:06 -04:00
Mike Bayer a8dc787ff0 - [feature] IdentitySet supports the - operator
as the same as difference(), handy when dealing
with Session.dirty etc. [ticket:2301]
2011-12-06 13:22:59 -05:00
Mike Bayer 3daae3e5b6 - Added an improved repr() to TypeEngine objects
that will only display constructor args which
are positional or kwargs that deviate
from the default.  [ticket:2209]
2011-07-04 13:56:17 -04:00
Mike Bayer 7b24e458c7 - move all the comments that got shoved below the fixture grabs back up 2011-03-27 17:19:00 -04:00
Mike Bayer 68a350d462 - remove test.sql._base, test.engine._base, test.orm._base, move those classes to a new test.lib.fixtures module
- move testing.TestBase to test.lib.fixtures
- massive search and replace
2011-03-27 16:27:27 -04:00
Mike Bayer b1b8e7defd - alex gaynor's latest batch of pypy test fixes 2011-03-16 13:04:07 -04:00
Mike Bayer eee9b55f0c rename 'frozendict' to 'immutabledict', since 'frozen' implies hashability
like frozenset which isn't really the purpose of 'immutabledict' (could be someday,
in which case, we'd change the name back :) )
2011-01-20 13:32:59 -05:00
Mike Bayer 350aed3fdb - whitespace removal bonanza 2011-01-02 14:23:42 -05:00
Mike Bayer f1e54a69fb - merge default tip 2010-12-05 14:56:26 -05:00
Mike Bayer 77f641429f - Fixed operator precedence rules for multiple
chains of a single non-associative operator.
I.e. "x - (y - z)" will compile as "x - (y - z)"
and not "x - y - z".  Also works with labels,
i.e. "x - (y - z).label('foo')"
[ticket:1984]
- Single element tuple expressions inside an IN clause
parenthesize correctly, also from [ticket:1984],
added tests for PG
- re-fix again importlater, [ticket:1983]
2010-11-25 12:20:13 -05:00