jun923.gu [Fri, 30 Nov 2018 05:21:29 +0000 (00:21 -0500)]
Add the write_timeout option for mysql.
As MySQLdb support read_timeout and write_timeout option, and
sqlalchemy just support read_timeout option. So sqlalchemy need to add
write_timeout option.
Mike Bayer [Mon, 26 Nov 2018 05:59:01 +0000 (00:59 -0500)]
Warn for lower-case column attribute on declarative
A warning is emitted in the case that a :func:`.column` object is applied to
a declarative class, as it seems likely this intended to be a
:class:`.Column` object.
Mike Bayer [Fri, 16 Nov 2018 00:48:45 +0000 (19:48 -0500)]
Repair tutorial code example to be deterministic
A few queries featured an aggregate without a GROUP BY
or a complete ordering, causing the doctests to fail
with recent versions of SQLite. The queries are now made
to include a GROUP BY as well as ORDER BY both columns.
Mike Bayer [Wed, 14 Nov 2018 16:02:40 +0000 (11:02 -0500)]
Add secondary selectable to FROM clauses for correlated exists
In continuing with a similar theme as that of very recent :ticket:`4349`,
repaired issue with :meth:`.RelationshipProperty.Comparator.any` and
:meth:`.RelationshipProperty.Comparator.has` where the "secondary"
selectable needs to be explicitly part of the FROM clause in the
EXISTS subquery to suit the case where this "secondary" is a :class:`.Join`
object.
Mike Bayer [Wed, 14 Nov 2018 16:31:22 +0000 (11:31 -0500)]
Deannotate "parententity" in primaryjoin/secondaryjoin
Fixed bug where the ORM annotations could be incorrect for the
primaryjoin/secondaryjoin a relationship if one used the pattern
``ForeignKey(SomeClass.id)`` in the declarative mappings. This pattern
would leak undesired annotations into the join conditions which can break
aliasing operations done within :class:`.Query` that are not supposed to
impact elements in that join condition. These annotations are now removed
up front if present.
Also add a test suite for has/any into test_query which will
form the basis for new tests to be added in :ticket:`4366`.
Mike Bayer [Mon, 12 Nov 2018 20:09:37 +0000 (15:09 -0500)]
Insert primary entity in dynamic "secondary"
Fixed regression caused by :ticket:`4349` where adding the "secondary"
table to the FROM clause for a dynamic loader would affect the ability of
the :class:`.Query` to make a subsequent join to another entity. The fix
adds the primary entity as the first element of the FROM list since
:meth:`.Query.join` wants to jump from that. Version 1.3 will have
a more comprehensive solution to this problem as well (:ticket:`4365`).
Mike Bayer [Sat, 10 Nov 2018 04:18:55 +0000 (23:18 -0500)]
Use case insensitive matching on lower_case_table_names=1,2
Fixed regression caused by :ticket:`4344` released in 1.2.13, where the fix
for MySQL 8.0's case sensitivity problem with referenced column names when
reflecting foreign key referents is worked around using the
``information_schema.columns`` view. The workaround was failing on OSX /
``lower_case_table_names=2`` which produces non-matching casing for the
``information_schema.columns`` vs. that of ``SHOW CREATE TABLE``, so in
case-insensitive SQL modes case-insensitive matching is now used.
Mike Bayer [Tue, 6 Nov 2018 20:13:03 +0000 (15:13 -0500)]
Improve documentation re: Session.binds and partitioning strategies
Update documentation to include background on arbitrary superclass
usage, add full cross-linking between all related methods and parameters.
De-emphasize "twophase" and document that it is not well-supported
in drivers.
Mike Bayer [Fri, 2 Nov 2018 20:40:59 +0000 (16:40 -0400)]
Deannotate ORM columns in ColumnEntity
Fixed a minor performance issue which could in some cases add unnecessary
overhead to result fetching, involving the use of ORM columns and entities
that include those same columns at the same time within a query. The issue
has to do with hash / eq overhead when referring to the column in different
ways.
Mike Bayer [Fri, 2 Nov 2018 01:53:18 +0000 (21:53 -0400)]
Use attr keys when testing bulk update params for primary key
Fixed bug in :meth:`.Session.bulk_update_mappings` where alternate mapped
attribute names would result in the primary key column of the UPDATE
statement being included in the SET clause, as well as the WHERE clause;
while usually harmless, for SQL Server this can raise an error due to the
IDENTITY column. This is a continuation of the same bug that was fixed in
:ticket:`.3849`, where testing was insufficient to catch this additional
flaw.
Tom Manderson [Tue, 30 Oct 2018 17:05:43 +0000 (13:05 -0400)]
Move pk on single-inh subclass check below conflict resolution check
The column conflict resolution technique discussed at
:ref:`declarative_column_conflicts` is now functional for a :class:`.Column`
that is also a primary key column. Previously, a check for primary key
columns declared on a single-inheritance subclass would occur before the
column copy were allowed to pass.
Mike Bayer [Sun, 21 Oct 2018 02:20:06 +0000 (22:20 -0400)]
Use the same "current_timestamp" function for both sides of round trip
this test was using sysdate() and current_timestamp() together
in conjunction with a truncation to DAY, however for four hours
on saturday night (see commit time :) ) these two values will
have a different value if one side is EDT and the other is UTC.
tox does not transmit environment variables including TZ by
default, so even if the server is set up for EDT, running tox
will not set TZ and at least Oracle client seems to use this
value, producing UTC for session time but the database on CI
was configured for EDT, producing EDT for sysdate.
Mike Bayer [Fri, 19 Oct 2018 21:10:42 +0000 (17:10 -0400)]
Check more specifically for hybrid attr and not mapped property
Fixed regression caused by :ticket:`4326` in version 1.2.12 where using
:class:`.declared_attr` with a mixin in conjunction with
:func:`.orm.synonym` would fail to map the synonym properly to an inherited
subclass.
Mike Bayer [Wed, 17 Oct 2018 14:42:50 +0000 (10:42 -0400)]
Add prop.secondary to FROM for dynamic loader
Fixed bug where "dynamic" loader needs to explicitly set the "secondary"
table in the FROM clause of the query, to suit the case where the secondary
is a join object that is otherwise not pulled into the query from its
columns alone.
Mike Bayer [Mon, 15 Oct 2018 05:44:13 +0000 (01:44 -0400)]
Don't use "is" to compare exceptions
psycopg2 is introducing a fine grained exception model where
most exceptions will be specialized subclasses, so don't use
"is" to compare an expression type
Mike Bayer [Sun, 14 Oct 2018 19:55:46 +0000 (15:55 -0400)]
Don't call rollback on DBAPI connection that's "closed"
Use the existence of ConnectionRecord.connection to estimate
that this connection is likely closed, and if so, don't
try to call "rollback" on it. This rollback is normally harmless
but is causing segfaults in mysqlclient due to
https://github.com/PyMySQL/mysqlclient-python/issues/270.
Mike Bayer [Tue, 2 Oct 2018 21:49:44 +0000 (17:49 -0400)]
Perform additional retrieval of correct column names
Added a workaround for a MySQL bug #88718 introduced in the 8.0 series,
where the reflection of a foreign key constraint is not reporting the
correct case sensitivity for the referred column, leading to errors during
use of the reflected constraint such as when using the automap extension.
The workaround emits an additional query to the information_schema tables in
order to retrieve the correct case sensitive name.
Joe Urciuoli [Wed, 19 Sep 2018 17:40:23 +0000 (13:40 -0400)]
Fix dependency_for final argument
Fixed issue where part of the utility language helper internals was passing
the wrong kind of argument to the Python ``__import__`` builtin as the list
of modules to be imported. The issue produced no symptoms within the core
library but could cause issues with external applications that redefine the
``__import__`` builtin or otherwise instrument it. Pull request courtesy Joe
Urciuoli.
Per the submitter: "The fourth argument provided to `__import__` (which
`import_` feeds in to) is supposed to be a a list of strings, but this code is
passing a single string. This was causing the sqlalchemy `import_` function to
break the string (for example 'interfaces') into an array of single characters
['i', 'n', ...], which causes the actual `__import__` to not find the module
`sqlalchemy.orm.i` (since it's trying to import `sqlalchemy.orm.i` and
`sqlalchemy.orm.n` .. etc)"
No issue could be reproduced locally as it seems you can put anything non-
empty/None into that last argument, even a list like ``['X']``, and all the
sub-modules seem to appear. Omit it, and then the sub-modules aren't present.
Perhaps it just runs the module or not if this attribute is present.
Change-Id: Ia15c74620f24d24f0df4882f9b36a04e2c3725b8
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/473
(cherry picked from commit cacc3c2057ab14faaf6c5b679bb2dbb6f8b98f8e)
Fixed additional warnings generated by Python 3.7 due to changes in the
organization of the Python ``collections`` and ``collections.abc`` packages.
Previous ``collections`` warnings were fixed in version 1.2.11. Pull request
courtesy xtreak.
See I2d1c0ef97c8ecac7af152cc56263422a40faa6bb for the original collections.abc
fixes.
Mike Bayer [Tue, 25 Sep 2018 14:38:40 +0000 (10:38 -0400)]
Copy create_constraint flag for Enum
Fixed bug where the :paramref:`.Enum.create_constraint` flag on the
:class:`.Enum` datatype would not be propagated to copies of the type, which
affects use cases such as declarative mixins and abstract bases.
Samuel Chou [Wed, 19 Sep 2018 17:30:24 +0000 (13:30 -0400)]
Allow dialects to customize group by clause compilation
Refactored :class:`.SQLCompiler` to expose a
:meth:`.SQLCompiler.group_by_clause` method similar to the
:meth:`.SQLCompiler.order_by_clause` and :meth:`.SQLCompiler.limit_clause`
methods, which can be overridden by dialects to customize how GROUP BY
renders. Pull request courtesy Samuel Chou.
Change-Id: I0a7238e55032558c27a0c56a72907c7b883456f1
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/474
(cherry picked from commit 33fccc486111fc6b41eab651cc7325c83099ad45)
Mike Bayer [Mon, 17 Sep 2018 15:38:52 +0000 (11:38 -0400)]
Adapt right side in join if lateral detected
Fixed bug where use of :class:`.Lateral` construct in conjunction with
:meth:`.Query.join` as well as :meth:`.Query.select_entity_from` would not
apply clause adaption to the right side of the join. "lateral" introduces
the use case of the right side of a join being correlatable. Previously,
adaptation of this clause wasn't considered.
Added a check within the weakref cleanup for the :class:`.InstanceState`
object to check for the presence of the ``dict`` builtin, in an effort to
reduce error messages generated when these cleanups occur during interpreter
shutdown. Pull request courtesy Romuald Brunet.
Change-Id: If27b94d50a32767de8b4147c09fa423f71596004
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/472
(cherry picked from commit 505941259e4e7181a176e74b3de0b7d96c444e29)
Mike Bayer [Mon, 17 Sep 2018 18:05:46 +0000 (14:05 -0400)]
Use cx_Oracle dml_ret_array_val
Fixed issue for cx_Oracle 7.0 where the behavior of Oracle param.getvalue()
now returns a list, rather than a single scalar value, breaking
autoincrement logic throughout the Core and ORM. The dml_ret_array_val
compatibility flag is used for cx_Oracle 6.3 and 6.4 to establish compatible
behavior with 7.0 and forward, for cx_Oracle 6.2.1 and prior a version
number check falls back to the old logic.
Mike Bayer [Thu, 6 Sep 2018 14:44:09 +0000 (10:44 -0400)]
Clarify init_scalar event use case
Since I didn't even realize what this was for when reading the docs,
make it clearer that this is to mirror a Column default and remove
the extra verbiage about the mechanics of INSERTs.
Mike Bayer [Thu, 30 Aug 2018 21:12:58 +0000 (17:12 -0400)]
MariaDB 10.3 updates
MariaDB seems to handle some additional UPDATE/DELETE FROM
syntaxes as well as some forms of INTERSECT and EXCEPT. Open
up tests that expect failure for MySQL to allow success for
MariaDB 10.3.
Mike Bayer [Sun, 26 Aug 2018 16:35:59 +0000 (12:35 -0400)]
Include Session._query_cls as part of the cache key
Fixed issue where :class:`.BakedQuery` did not include the specific query
class used by the :class:`.Session` as part of the cache key, leading to
incompatibilities when using custom query classes, in particular the
:class:`.ShardedQuery` which has some different argument signatures.
Mike Bayer [Thu, 23 Aug 2018 16:40:26 +0000 (12:40 -0400)]
Unwrap Proxy objects when scanning declared_attr
Fixed bug where the declarative scan for attributes would receive the
expression proxy delivered by a hybrid attribute at the class level, and
not the hybrid attribute itself, when receiving the descriptor via the
``@declared_attr`` callable on a subclass of an already-mapped class. This
would lead to an attribute that did not report itself as a hybrid when
viewed within :attr:`.Mapper.all_orm_descriptors`.
Mike Bayer [Thu, 23 Aug 2018 15:55:13 +0000 (11:55 -0400)]
Don't run postfetch_post_update for a DELETE
Fixed 1.2 regression caused by :ticket:`3472` where the handling of an
"updated_at" style column within the context of a post-update operation
would also occur for a row that is to be deleted following the update,
meaning both that a column with a Python-side value generator would show
the now-deleted value that was emitted for the UPDATE before the DELETE
(which was not the previous behavor), as well as that a SQL- emitted value
generator would have the attribute expired, meaning the previous value
would be unreachable due to the row having been deleted and the object
detached from the session.The "postfetch" logic that was added as part of
:ticket:`3472` is now skipped entirely for an object that ultimately is to
be deleted.
Mike Bayer [Wed, 22 Aug 2018 15:13:54 +0000 (11:13 -0400)]
Pass desired array type from pg.array_agg to functions.array_agg
Fixed the :func:`.postgresql.array_agg` function, which is a slightly
altered version of the usual :func:`.functions.array_agg` function, to also
accept an incoming "type" argument without forcing an ARRAY around it,
essentially the same thing that was fixed for the generic function in 1.1
in :ticket:`4107`.
Mike Bayer [Wed, 22 Aug 2018 00:59:04 +0000 (20:59 -0400)]
Strip quotes from format_type in addition to other characters
Fixed bug in PostgreSQL ENUM reflection where a case-sensitive, quoted name
would be reported by the query including quotes, which would not match a
target column during table reflection as the quotes needed to be stripped
off.
Mike Bayer [Mon, 20 Aug 2018 02:19:59 +0000 (22:19 -0400)]
Add missing range_ / rows parameters to additional over() methods
Added missing window function parameters
:paramref:`.WithinGroup.over.range_` and :paramref:`.WithinGroup.over.rows`
parameters to the :meth:`.WithinGroup.over` and
:meth:`.FunctionFilter.over` methods, to correspond to the range/rows
feature added to the "over" method of SQL functions as part of
:ticket:`3049` in version 1.1.
Mike Bayer [Fri, 17 Aug 2018 15:37:30 +0000 (11:37 -0400)]
Accommodate for classically mapped base classes in declarative
Fixed issue in previously untested use case, allowing a declarative mapped
class to inherit from a classically-mapped class outside of the declarative
base, including that it accommodates for unmapped intermediate classes. An
unmapped intermediate class may specify ``__abstract__``, which is now
interpreted correctly, or the intermediate class can remain unmarked, and
the classically mapped base class will be detected within the hierarchy
regardless. In order to anticipate existing scenarios which may be mixing
in classical mappings into existing declarative hierarchies, an error is
now raised if multiple mapped bases are detected for a given class.
Mike Bayer [Wed, 15 Aug 2018 21:11:14 +0000 (17:11 -0400)]
Add concept of "implicit boolean", treat as native
Fixed issue that is closely related to :ticket:`3639` where an expression
rendered in a boolean context on a non-native boolean backend would
be compared to 1/0 even though it is already an implcitly boolean
expression, when :meth:`.ColumnElement.self_group` were used. While this
does not affect the user-friendly backends (MySQL, SQLite) it was not
handled by Oracle (and possibly SQL Server). Whether or not the
expression is implicitly boolean on any database is now determined
up front as an additional check to not generate the integer comparison
within the compliation of the statement.
Mike Bayer [Sat, 4 Aug 2018 17:45:07 +0000 (13:45 -0400)]
Include UPDATE/DELETE extra_froms in correlation
Fixed bug where the multi-table support for UPDATE and DELETE statements
did not consider the additional FROM elements as targets for correlation,
when a correlated SELECT were also combined with the statement. This
change now includes that a SELECT statement in the WHERE clause for such a
statement will try to auto-correlate back to these additional tables in the
parent UPDATE/DELETE or unconditionally correlate if
:meth:`.Select.correlate` is used. Note that auto-correlation raises an
error if the SELECT statement would have no FROM clauses as a result, which
can now occur if the parent UPDATE/DELETE specifies the same tables in its
additional set of tables ; specify :meth:`.Select.correlate` explicitly to
resolve.
Mike Bayer [Wed, 1 Aug 2018 18:12:49 +0000 (14:12 -0400)]
Bind Integers to int for cx_Oracle
For cx_Oracle, Integer datatypes will now be bound to "int", per advice
from the cx_Oracle developers. Previously, using cx_Oracle.NUMBER caused a
loss in precision within the cx_Oracle 6.x series.
Started importing "collections" from "collections.abc" under Python 3.3 and
greater for Python 3.8 compatibility. Pull request courtesy Nathaniel
Knight.
In Python 3.3, the abstract base classes (Iterable, Mapping, etc.)
were moved from the `collections` module and put in the
`collections.abc` module. They remain in the `collections` module for
backwards compatibility, and will until Python 3.8.
This commit adds a variable (`collections_abc`) to the `util/compat`
module, which will be the `collections` module for Python < 3.3 and
before, or the `collections.abc` module for Python >= 3.3. It also
uses the new variable, getting rid of some deprecation warnings that
were seen when running under Python 3.7.
Change-Id: I2d1c0ef97c8ecac7af152cc56263422a40faa6bb
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/464
(cherry picked from commit a59c3b8f302a34ab037ec445b7452b1f353b91af)
Mike Bayer [Wed, 1 Aug 2018 16:27:22 +0000 (12:27 -0400)]
Correct sharding tests for provisioned follower
The sharding tests created named sqlite databases that were
shared across test suites. It is unknown why these suddenly
started failing and were not failing before.
Fix quoting schemas in _get_table_sql for the SQLite backend
Fixed issue where the "schema" name used for a SQLite database within table
reflection would not quote the schema name correctly. Pull request
courtesy Phillip Cloud.
Change-Id: I2770788c1f094a7743209250ec26b5ef5fb2d9e8
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/463
(cherry picked from commit 893eac06e511f3765c0c89bab76d7933d83ffccc)
Mike Bayer [Fri, 13 Jul 2018 16:58:21 +0000 (12:58 -0400)]
Use exprs for bundle __clause_element__
Fixed bug in :class:`.Bundle` construct where placing two columns of the
same name would be de-duplicated, when the :class:`.Bundle` were used as
part of the rendered SQL, such as in the ORDER BY or GROUP BY of the statement.
Mike Bayer [Tue, 10 Jul 2018 13:41:21 +0000 (09:41 -0400)]
Drop default-related structures after the Table is dropped.
Fixed bug where a :class:`.Sequence` would be dropped explicitly before any
:class:`.Table` that refers to it, which breaks in the case when the
sequence is also involved in a server-side default for that table, when
using :meth:`.MetaData.drop_all`. The step which processes sequences
to be dropped via non server-side column default functions is now invoked
after the table itself is dropped.