Miguel Ventura [Mon, 14 May 2018 20:56:58 +0000 (16:56 -0400)]
Fix string formatting TypeError if tuple is passed
Fixed issue where the "ambiguous literal" error message used when
interpreting literal values as SQL expression values would encounter a
tuple value, and fail to format the message properly. Pull request courtesy
Miguel Ventura.
Change-Id: I50d5d32d5f80ec79703a42d4b19b42c2f9701f24
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/442
(cherry picked from commit 0b0b58c938c6a38fccc3e0ba59876b3b6b4f8009)
Mike Bayer [Wed, 16 May 2018 15:16:57 +0000 (11:16 -0400)]
Change query._identity_lookup into a normal instance method
Fixed regression in 1.2.7 caused by :ticket:`4228`, which itself was fixing
a 1.2-level regression, where the ``query_cls`` callable passed to a
:class:`.Session` was assumed to be a subclass of :class:`.Query` with
class method availability, as opposed to an arbitrary callable. In
particular, the dogpile caching example illustrates ``query_cls`` as a
function and not a :class:`.Query` subclass.
Mike Bayer [Mon, 26 Feb 2018 00:54:37 +0000 (19:54 -0500)]
Merge existing query params in baked lazy load
Corrected backport, was supposed to be in 1.2.5 however
never got backported.
Fixed a long-standing regression that occurred in version
1.0, which prevented the use of a custom :class:`.MapperOption`
that alters the _params of a :class:`.Query` object for a
lazy load, since the lazy loader itself would overwrite those
parameters. This applies to the "temporal range" example
on the wiki. Note however that the
:meth:`.Query.populate_existing` method is now required in
order to rewrite the mapper options associated with an object
already loaded in the identity map.
As part of this change, a custom defined
:class:`.MapperOption` will now cause lazy loaders related to
the target object to use a non-baked query by default unless
the :meth:`.MapperOption._generate_cache_key` method is implemented.
In particular, this repairs one regression which occured when
using the dogpile.cache "advanced" example, which was not
returning cached results and instead emitting SQL due to an
incompatibility with the baked query loader; with the change,
the ``RelationshipCache`` option included for many releases
in the dogpile example will disable the "baked" query altogether.
Note that the dogpile example is also modernized to avoid both
of these issues as part of issue :ticket:`4258`.
Mike Bayer [Tue, 15 May 2018 20:15:51 +0000 (16:15 -0400)]
Prevent double-checkins and guard during reset-on-return invalidations
Fixed connection pool issue whereby if a disconnection error were raised
during the connection pool's "reset on return" sequence in conjunction with
an explicit transaction opened against the enclosing :class:`.Connection`
object (such as from calling :meth:`.Session.close` without a rollback or
commit, or calling :meth:`.Connection.close` without first closing a
transaction declared with :meth:`.Connection.begin`), a double-checkin would
result, which could then lead towards concurrent checkouts of the same
connection. The double-checkin condition is now prevented overall by an
assertion, as well as the specific double-checkin scenario has been
fixed.
Mike Bayer [Thu, 3 May 2018 16:35:23 +0000 (12:35 -0400)]
Use identity_token for refresh(), unexpire, undefer
The horizontal sharding extension now makes use of the identity token
added to ORM identity keys as part of :ticket:`4137`, when an object
refresh or column-based deferred load or unexpiration operation occurs.
Since we know the "shard" that the object originated from, we make
use of this value when refreshing, thereby avoiding queries against
other shards that don't match this object's identity in any case.
Mike Bayer [Fri, 11 May 2018 13:19:10 +0000 (09:19 -0400)]
Default server_version_info to (0, )
Fixed a bug in the test suite where if an external dialect returned
``None`` for ``server_version_info``, the exclusion logic would raise an
``AttributeError``.
Mike Bayer [Thu, 10 May 2018 15:39:06 +0000 (11:39 -0400)]
SQL Server is not native boolean; add new flag for CHECK constraint
Fixed a 1.2 regression caused by :ticket:`4061` where the SQL Server
"BIT" type would be considered to be "native boolean". The goal here
was to avoid creating a CHECK constraint on the column, however the bigger
issue is that the BIT value does not behave like a true/false constant
and cannot be interpreted as a standalone expression, e.g.
"WHERE <column>". The SQL Server dialect now goes back to being
non-native boolean, but with an extra flag that still avoids creating
the CHECK constraint.
Fixed a reference leak issue where the values of the parameter dictionary
used in a statement execution would remain referenced by the "compiled
cache", as a result of storing the key view used by Python 3 dictionary
keys(). Pull request courtesy Olivier Grisel.
Change-Id: Icfb0f38111a165780f6dd3e4e3382a03df79ce26
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/441
(cherry picked from commit 30b02003a70f37aa83e20de6229afe2a3600b648)
Mike Bayer [Fri, 20 Apr 2018 15:44:09 +0000 (11:44 -0400)]
Refactor "get" to allow for pluggable identity token schemes
Fixed regression in 1.2 within sharded query feature where the
new "identity_token" element was not being correctly considered within
the scope of a lazy load operation, when searching the identity map
for a related many-to-one element. The new behavior will allow for
making use of the "id_chooser" in order to determine the best identity
key to retrieve from the identity map. In order to achieve this, some
refactoring of 1.2's "identity_token" approach has made some slight changes
to the implementation of ``ShardedQuery`` which should be noted for other
derivations of this class.
Mike Bayer [Fri, 20 Apr 2018 17:31:45 +0000 (13:31 -0400)]
Document how to opt-out of NCHAR for cx_Oracle
Unfortunately, we need to bind Python unicode values as
NCHAR as in the case where non-ascii characters are present,
it's necessary. We can't know in all cases how this value is being
used, so in those cases where Oracle will not accept NCHAR the
user should explicitly cast a value down to String.
Mike Bayer [Thu, 19 Apr 2018 21:07:32 +0000 (17:07 -0400)]
Ensure select_from_entity adapter is used in adjust_for_single_inheritance
Fixed issue in single-inheritance loading where the use of an aliased
entity against a single-inheritance subclass in conjunction with the
:meth:`.Query.select_from` method would cause the SQL to be rendered with
the unaliased table mixed in to the query, causing a cartesian product. In
particular this was affecting the new "selectin" loader when used against a
single-inheritance subclass.
Kent Bower [Wed, 11 Apr 2018 21:21:26 +0000 (17:21 -0400)]
Reflect Oracle NUMBER(NULL, 0) as INTEGER
The Oracle NUMBER datatype is reflected as INTEGER if the precision is NULL
and the scale is zero, as this is how INTEGER values come back when
reflected from Oracle's tables. Pull request courtesy Kent Bower.
Change-Id: I4627febd46cab7085299c0a5700ee0f0bdca513c
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/437
(cherry picked from commit a3473c08d35e2cce32b014519df5f774c0166cf1)
Mike Bayer [Wed, 11 Apr 2018 13:29:00 +0000 (09:29 -0400)]
Correct join for FKs with schema in SQL Server
Fixed 1.2 regression caused by :ticket:`4060` where the query used to
reflect SQL Server cross-schema foreign keys was limiting the criteria
incorrectly.
Additionally, added some rework of the inter-schema reflection tests
so that MySQL, MSSQL can be included, breaking out some of the
Postgresql-specific behaviors into separate requirements.
Mike Bayer [Wed, 4 Apr 2018 17:36:28 +0000 (13:36 -0400)]
Ensure all visit_sequence accepts **kw args
Fixed issue where the compilation of an INSERT statement with the
"literal_binds" option that also uses an explicit sequence and "inline"
generation, as on Postgresql and Oracle, would fail to accommodate the
extra keyword argument within the sequence processing routine.
Mike Bayer [Tue, 3 Apr 2018 19:35:00 +0000 (15:35 -0400)]
Use base __ne__ implementation for range types w/ None
Fixed bug where the special "not equals" operator for the Postgresql
"range" datatypes such as DATERANGE would fail to render "IS NOT NULL" when
compared to the Python ``None`` value.
Also break up range tests into backend round trip and straight
compilation suites.
Mike Bayer [Fri, 30 Mar 2018 15:22:30 +0000 (11:22 -0400)]
Filter non-integer characters from pyodbc SQL Server version
Adjusted the SQL Server version detection for pyodbc to only allow for
numeric tokens, filtering out non-integers, since the dialect does tuple-
numeric comparisons with this value. This is normally true for all known
SQL Server / pyodbc drivers in any case.
Mike Bayer [Wed, 28 Mar 2018 15:58:47 +0000 (11:58 -0400)]
Invalidate on failed connect handler
Fixed bug in connection pool where a connection could be present in the
pool without all of its "connect" event handlers called, if a previous
"connect" handler threw an exception; note that the dialects themselves
have connect handlers that emit SQL, such as those which set transaction
isolation, which can fail if the database is in a non-available state, but
still allows a connection. The connection is now invalidated first if any
of the connect handlers fail.
Mike Bayer [Wed, 21 Mar 2018 13:59:46 +0000 (09:59 -0400)]
Don't warn for mixin-based __table_args__, __mapper_args__ declared_attr
Removed a warning that would be emitted when calling upon
``__table_args__``, ``__mapper_args__`` as named with a ``@declared_attr``
method, when called from a non-mapped declarative mixin. Calling these
directly is documented as the approach to use when one is overidding one
of these methods on a mapped class. The warning still emits for regular
attribute names.
Mike Bayer [Wed, 14 Mar 2018 15:04:43 +0000 (11:04 -0400)]
Track if we're rendering within the CTE recursively
Fixed a regression that occurred from the previous fix to :ticket:`4204` in
version 1.2.5, where a CTE that refers to itself after the
:meth:`.CTE.alias` method has been called would not refer to iself
correctly.
Mike Bayer [Mon, 12 Mar 2018 16:50:52 +0000 (12:50 -0400)]
Ignore non-primary mappers within mutable instrumentation
Fixed bug where using :meth:`.Mutable.associate_with` or
:meth:`.Mutable.as_mutable` in conjunction with a class that has non-
primary mappers set up with alternatively-named attributes would produce an
attribute error. Since non-primary mappers are not used for persistence,
the mutable extension now excludes non-primary mappers from its
instrumentation steps.
Mike Bayer [Wed, 7 Mar 2018 21:27:26 +0000 (16:27 -0500)]
Raise cx_Oracle minimum version to 5.2
The minimum cx_Oracle version supported is 5.2 (June 2015). Previously,
the dialect asserted against version 5.0 but as of 1.2.2 we are using some
symbols that did not appear until 5.2.
Mike Bayer [Wed, 7 Mar 2018 21:03:07 +0000 (16:03 -0500)]
Add notes regarding flat=True
Start documenting that flat=True and aliased=True don't work
with selectable particularly when selectable is an aliased select
already. References #4212
Eric Atkin [Wed, 28 Feb 2018 21:00:38 +0000 (16:00 -0500)]
Add Query.enable_single_entity()
Added new feature :meth:`.Query.only_return_tuples`. Causes the
:class:`.Query` object to return keyed tuple objects unconditionally even
if the query is against a single entity. Pull request courtesy Eric
Atkin.
Change-Id: Ib0b7f5f78431aa68082e5b200ed577daa4222336
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/425
(cherry picked from commit 451f81ef53a8065db20257af2a4a245196cc07d9)
Mike Bayer [Tue, 6 Mar 2018 02:36:18 +0000 (21:36 -0500)]
Clone _cte_alias instead of assigning "self"
Fixed bug in :class:.`CTE` construct along the same lines as that of
:ticket:`4204` where a :class:`.CTE` that was aliased would not copy itself
correctly during a "clone" operation as is frequent within the ORM as well
as when using the :meth:`.ClauseElement.params` method.
Mike Bayer [Mon, 5 Mar 2018 19:48:00 +0000 (14:48 -0500)]
Don't include AliasedClass when pickling options
Fixed 1.2 regression where a mapper option that contains an
:class:`.AliasedClass` object, as is typical when using the
:meth:`.QueryableAttribute.of_type` method, could not be pickled. 1.1's
behavior was to omit the aliased class objects from the path, so this
behavior is restored.
Mike Bayer [Mon, 5 Mar 2018 16:33:30 +0000 (11:33 -0500)]
Only replace first occurrence for COLLATE/ARRAY syntax
Fixed bug in Postgresql COLLATE / ARRAY adjustment first introduced
in :ticket:`4006` where new behaviors in Python 3.7 regular expressions
caused the fix to fail.
Mike Bayer [Fri, 2 Mar 2018 20:08:08 +0000 (15:08 -0500)]
Get MySQL version info from @@version
MySQL dialects now query the server version using ``SELECT @@version``
explicitly to the server to ensure we are getting the correct version
information back. Proxy servers like MaxScale interfere with the value
that is passed to the DBAPI's connection.server_version value so this
is no longer reliable.
Mike Bayer [Thu, 1 Mar 2018 15:45:39 +0000 (10:45 -0500)]
Check existing CTE for an alias name when rendering FROM clause
Fixed bug in CTE rendering where a :class:`.CTE` that was also turned into
an :class:`.Alias` would not render its "ctename AS aliasname" clause
appropriately if there were more than one reference to the CTE in a FROM
clause.
Mike Bayer [Fri, 23 Feb 2018 18:55:17 +0000 (13:55 -0500)]
Ensure we have states to load when doing poly post load
Fixed bug in new "polymorphic selectin" loading when a selection of
polymorphic objects were to be partially loaded from a relationship
lazy loader, leading to an "empty IN" condition within the load that
raises an error for the "inline" form of "IN".
Mike Bayer [Fri, 23 Feb 2018 00:47:24 +0000 (19:47 -0500)]
Allow bind processors to work with expanding IN
Fixed bug in new "expanding IN parameter" feature where the bind parameter
processors for values wasn't working at all, tests failed to cover this
pretty basic case which includes that ENUM values weren't working.
Eric Atkin [Thu, 22 Feb 2018 19:16:14 +0000 (14:16 -0500)]
Quote cte alias if needed
Fixed bug where CTE expressions would not have their name or alias name
quoted when the given name is case sensitive or otherwise requires quoting.
Pull request courtesy Eric Atkin.
Mike Bayer [Wed, 21 Feb 2018 16:16:09 +0000 (11:16 -0500)]
Ensure mapping has no version_id_generator when checking missing version_id
Fixed 1.2 regression in ORM versioning feature where a mapping against a
:func:`.select` or :func:`.alias` that also used a versioning column
against the underlying table would fail due to the check added as part of
:ticket:`3673`.
See also #4194 and #4195 for related issues found regarding
mapped selects and versioning.
Mike Bayer [Tue, 20 Feb 2018 17:15:57 +0000 (12:15 -0500)]
Default to using current mapped class as owner if none found
Repaired regression caused in 1.2.3 and 1.1.16 regarding association proxy
objects, revising the approach to :ticket:`4185` when calculating the
"owning class" of an association proxy to default to choosing the current
class if the proxy object is not directly associated with a mapped class,
such as a mixin.
Mike Bayer [Mon, 19 Feb 2018 23:13:24 +0000 (18:13 -0500)]
Rewrite the "deleting from collections" section
This section documents an aspect of the ORM that is
more generalized than just collections as well as more general
than just using session.delete(), even though session.delete()
with collections is the most common use case. Try to expand
out the scope here to explain the situation from the perspective
of any kind of relationship, include example with delete cascade
with many-to-one as well.
Mike Bayer [Mon, 19 Feb 2018 21:59:42 +0000 (16:59 -0500)]
Implement remove() for _empty_collection
Fixed regression caused in 1.2.3 due to fix from :ticket:`4181` where
the changes to the event system involving :class:`.Engine` and
:class:`.OptionEngine` did not accommodate for event removals, which
would raise an ``AttributeError`` when invoked at the class
level.
Mike Bayer [Fri, 16 Feb 2018 23:13:30 +0000 (18:13 -0500)]
Remove erroneous skip message
The logic here seems to try to say something different when
__backend__ is True but it produces a nonsensical message,
since __only_on__ doesn't tell us about the implementation
we are actually running.
Mike Bayer [Thu, 15 Feb 2018 22:42:48 +0000 (17:42 -0500)]
Test attributes for being non-mapped column properties more closely
Fixed bug in concrete inheritance mapping where user-defined
attributes such as hybrid properties that mirror the names
of mapped attributes from sibling classes would be overwritten by
the mapper as non-accessible at the instance level. Also
ensured that user-bound descriptors are not implicitly invoked at the class
level during the mapper configuration stage.
André Cruz [Thu, 15 Feb 2018 16:09:47 +0000 (11:09 -0500)]
Add ssl "operation timed out" message for psycopg2
Added "SSL SYSCALL error: Operation timed out" to the list
of messages that trigger a "disconnect" scenario for the
psycopg2 driver. Pull request courtesy André Cruz.
Mike Bayer [Tue, 13 Feb 2018 20:11:53 +0000 (15:11 -0500)]
Allow multiple plugin names
The :class:`.URL` object now allows query keys to be specified multiple
times where their values will be joined into a list. This is to support
the plugins feature documented at :class:`.CreateEnginePlugin` which
documents that "plugin" can be passed multiple times. Additionally, the
plugin names can be passed to :func:`.create_engine` outside of the URL
using the new :paramref:`.create_engine.plugins` parameter.
Mike Bayer [Mon, 12 Feb 2018 21:45:39 +0000 (16:45 -0500)]
Add dependency for parent_pre post updates to parent deletes
Fixed issue in post_update feature where an UPDATE is emitted
when the parent object has been deleted but the dependent object
is not. This issue has existed for a long time however
since 1.2 now asserts rows matched for post_update, this
was raising an error.
Mike Bayer [Fri, 9 Feb 2018 21:12:31 +0000 (16:12 -0500)]
Search through mapper superclass hierarchy for owner
Fixed regression caused by fix for issue :ticket:`4116` affecting versions
1.2.2 as well as 1.1.15, which had the effect of mis-calculation of the
"owning class" of an :class:`.AssociationProxy` as the ``NoneType`` class
in some declarative mixin/inheritance situations as well as if the
association proxy were accessed off of an un-mapped class. The "figure out
the owner" logic has been replaced by an in-depth routine that searches
through the complete mapper hierarchy assigned to the class or subclass to
determine the correct (we hope) match; will not assign the owner if no
match is found. An exception is now raised if the proxy is used
against an un-mapped instance.
Mike Bayer [Thu, 8 Feb 2018 14:16:39 +0000 (09:16 -0500)]
Add initiator argument to set_attribute
Added new argument :paramref:`.attributes.set_attribute.inititator`
to the :func:`.attributes.set_attribute` function, allowing an
event token received from a listener function to be propagated
to subsequent set events.
Mike Bayer [Thu, 8 Feb 2018 19:52:29 +0000 (14:52 -0500)]
Ensure weakref finalize_fairy operates upon the current connection
Fixed a fairly serious connection pool bug where a connection that is
acquired after being refreshed as a result of a user-defined
:class:`.DisconnectionError` or due to the 1.2-released "pre_ping" feature
would not be correctly reset if the connection were returned to the pool by
weakref cleanup (e.g. the front-facing object is garbage collected); the
weakref would still refer to the previously invalidated DBAPI connection
which would have the reset operation erroneously called upon it instead.
This would lead to stack traces in the logs and a connection being checked
into the pool without being reset, which can cause locking issues.
Jon Snyder [Wed, 17 Jan 2018 21:37:59 +0000 (16:37 -0500)]
Add values_callable feature to Enum
Added support for :class:`.Enum` to persist the values of the enumeration,
rather than the keys, when using a Python pep-435 style enumerated object.
The user supplies a callable function that will return the string values to
be persisted. This allows enumerations against non-string values to be
value-persistable as well. Pull request courtesy Jon Snyder.