Commit Graph

8067 Commits

Author SHA1 Message Date
mike bayer c8dea359db Merge "Apply path generation for superclasses to Load._set_path_strategy()" 2018-12-01 16:52:22 +00:00
Mike Bayer fb05e085fe Apply path generation for superclasses to Load._set_path_strategy()
Extended the fix first made as part of 🎫`3287`, where a loader option
made against a subclass using a wildcard would extend itself to include
application of the wildcard to attributes on the super classes as well, to a
"bound" loader option as well, e.g. in an expression like
``Load(SomeSubClass).load_only('foo')``.  Columns that are part of the
parent class of ``SomeSubClass`` will also be excluded in the same way as if
the unbound option ``load_only('foo')`` were used.

Fixes: #4373
Change-Id: I2eee0e587c34323a77df077b9cb699da370c403d
2018-11-30 14:36:20 -05:00
mike bayer 7940e7dc9c Merge "Add __clause_element__ to ColumnProperty" 2018-11-30 18:12:02 +00:00
mike bayer f916fa3b31 Merge "Add the write_timeout option for mysql." 2018-11-30 18:11:06 +00:00
mike bayer 39596f3398 Merge "Allow optional *args with base AnsiFunction" 2018-11-30 15:18:44 +00:00
jun923.gu 6a8454ded3 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.

Fixes: #4381
Change-Id: I2bea80bdd6f20fafc72b48fa0e5d795626d9d9b9
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4385
2018-11-30 00:22:58 -05:00
Mike Bayer 3ff3975767 Allow optional *args with base AnsiFunction
Amended the :class:`.AnsiFunction` class, the base of common SQL
functions like ``CURRENT_TIMESTAMP``, to accept positional arguments
like a regular ad-hoc function.  This to suit the case that many of
these functions on specific backends accept arguments such as
"fractional seconds" precision and such.  If the function is created
with arguments, it renders the the parenthesis and the arguments.  If
no arguents are present, the compiler generates the non-parenthesized form.

Fixes: #4386
Change-Id: Ic492ef177e4987cec99ec4d95f55292be8daa087
2018-11-29 23:46:42 -05:00
Raphael 0a0b36686d typo
typo
2018-11-29 19:11:24 -05:00
Mike Bayer 835444be72 Add __clause_element__ to ColumnProperty
Added a ``__clause_element__()`` method to :class:`.ColumnProperty` which
can allow the usage of a not-fully-declared column or deferred attribute in
a declarative mapped class slightly more friendly when it's used in a
constraint or other column-oriented scenario within the class declaration,
though this still can't work in open-ended expressions; prefer to call the
:attr:`.ColumnProperty.expression` attribute if receiving ``TypeError``.

Fixes: #4372
Change-Id: I5d3d1adb9c77de0566298bc2c46e9001d314b0c7
2018-11-27 20:12:16 -05:00
Mike Bayer 6ec40eca1a 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.

Fixes: #4374
Change-Id: I2e617ef65547162e3ba6587c168548ad0cf6203d
2018-11-26 01:12:01 -05:00
Mike Bayer f39a6216ee Version 1.3.0b2 placeholder 2018-11-16 23:13:08 -05:00
Mike Bayer e0e6fe44e3 Modernize cx_Oracle parameters
Updated the parameters that can be sent to the cx_Oracle DBAPI to both allow
for all current parameters as well as for future parameters not added yet.
In addition, removed unused parameters that were deprecated in version 1.2,
and additionally we are now defaulting "threaded" to False.

Fixes: #4369
Change-Id: I599668960e7b2d5bd1f5e6850e10b5b3ec215ed3
2018-11-15 12:56:37 -05:00
Mike Bayer 996727ed89 Modernize cx_oracle connect documentation
in preparation for #4369, however the documentation was
also inaccurate in that it did not mention connect_args.

Change-Id: I992e5f53ce16cc9c72d2c893a3ca798a9c2b4d07
2018-11-15 12:52:33 -05:00
mike bayer 1f69e9b94c Merge "Add secondary selectable to FROM clauses for correlated exists" 2018-11-15 15:17:59 +00:00
mike bayer bfd6f76a7d Merge "Allow join() to pick the best candidate from multiple froms/entities" 2018-11-15 15:05:11 +00:00
Mike Bayer 7dcfd1e019 Allow join() to pick the best candidate from multiple froms/entities
Refactored :meth:`.Query.join` to further clarify the individual components
of structuring the join. This refactor adds the ability for
:meth:`.Query.join` to determine the most appropriate "left" side of the
join when there is more than one element in the FROM list or the query is
against multiple entities.  In particular this targets the regression we
saw in 🎫`4363` but is also of general use.   The codepaths within
:meth:`.Query.join` are now easier to follow and the error cases are
decided more specifically at an earlier point in the operation.

Fixes: #4365
Change-Id: I403f451243904a020ceab4c3f94bead550c7b2d5
2018-11-14 21:35:15 -05:00
Mike Bayer fdfd168060 Add secondary selectable to FROM clauses for correlated exists
In continuing with a similar theme as that of very recent 🎫`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.

Fixes: #4366
Change-Id: Icd0d0c3871bbd0059f0c9256e2b980edc2c90551
2018-11-14 17:37:02 -05:00
mike bayer 0a07fd99db Merge "Add new parameters for IDENTITY start/increment in mssql" 2018-11-14 22:35:19 +00:00
Mike Bayer 6629d9f892 Add new parameters for IDENTITY start/increment in mssql
Deprecated the use of :class:`.Sequence` with SQL Server in order to affect
the "start" and "increment" of the IDENTITY value, in favor of new
parameters ``mssql_identity_start`` and ``mssql_identity_increment`` which
set these parameters directly.  :class:`.Sequence` will be used to generate
real ``CREATE SEQUENCE`` DDL with SQL Server in a future release.

Fixes: #4362
Change-Id: I1e69378c5c960ff0bc28137c923589692f1a918f
2018-11-14 17:34:52 -05:00
mike bayer fd8f0044fe Merge "Deannotate "parententity" in primaryjoin/secondaryjoin" 2018-11-14 19:22:25 +00:00
mike bayer 5eafe15901 Merge "Insert primary entity in dynamic "secondary"" 2018-11-14 19:20:30 +00:00
Mike Bayer 4ee5b2c4a9 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 🎫`4366`.

Fixes: #4367
Change-Id: I929ef983981bb49bf975f346950ebb0e19c986b8
2018-11-14 11:35:45 -05:00
mike bayer 616b226f74 Merge "Add Sequence to StrSQLCompiler" 2018-11-13 23:37:33 +00:00
Mike Bayer 40c1a46e99 Insert primary entity in dynamic "secondary"
Fixed regression caused by 🎫`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 (🎫`4365`).

Fixes: #4363
Change-Id: I1abbb6207722619dc5369e1fd96de43d60a1ee62
2018-11-13 18:36:24 -05:00
Mike Bayer 8318a98a60 Add Sequence to StrSQLCompiler
Added :class:`.Sequence` to the "string SQL" system that will render a
meaningful string expression (``"<next sequence value: my_sequence>"``)
when stringifying without a dialect a statement that includes a "sequence
nextvalue" expression, rather than raising a compilation error.

Fixes: #4144
Change-Id: Ia910f0e22008a7cde7597365954ede324101cf4d
2018-11-10 21:10:51 -05:00
mike bayer 6b84db83e0 Merge "Add new "all columns" naming convention tokens" 2018-11-11 01:58:18 +00:00
mike bayer 680835f815 Merge "Modernize deferred callable for many-to-one comparison" 2018-11-11 01:56:41 +00:00
Mike Bayer d5c2db437e Modernize deferred callable for many-to-one comparison
Improved the behavior of a relationship-bound many-to-one object expression
such that the retrieval of column values on the related object are now
resilient against the object being detached from its parent
:class:`.Session`, even if the attribute has been expired.  New features
within the :class:`.InstanceState` are used to memoize the last known value
of a particular column attribute before its expired, so that the expression
can still evaluate when the object is detached and expired at the same
time.  Error conditions are also improved using modern attribute state
features to produce more specific messages as needed.

To support the value being mutated while also being resilient towards
expiration, a new feature to InstanceState is added ._last_known_values
which holds onto the expired value when an individual key is expired.
Only takes effect specific to keys and InstanceState objects that
received a special instruction so this does not add to overall
memory/latency.

Fixes: #4359
Change-Id: Iff272e667bf741074549db550bf65348553ca8e7
2018-11-10 20:55:57 -05:00
Mike Bayer be70559584 Add new "all columns" naming convention tokens
Added new naming convention tokens ``column_0N_name``, ``column_0_N_name``,
etc., which will render the names / keys / labels for all columns referenced
by a particular constraint in a sequence.  In order to accommodate for the
length of such a naming convention, the SQL compiler's auto-truncation
feature now applies itself to constraint names as well, which creates a
shortened, deterministically generated name for the constraint that will
apply to a target backend without going over the character limit of that
backend.

Additional notes:

1. the SQLite dialect had a format_index method that was apparently not
used, removed.

2. the naming convention logic has been applying the foreign key
remote column spec to the naming convention, and not the actual
column name.  In the case where the referenced Table object uses
.key inside the columns and these are what ForeignKey() references,
the naming convention was doing the wrong thing.   The patch here
fixes this, however this isn't noted in the migration notes.

Fixes: #3989
Change-Id: Ib24f4754b886676096c480fc54b2e5c2463ac99a
2018-11-10 16:13:01 -05:00
Mike Bayer af159c5695 Use case insensitive matching on lower_case_table_names=1,2
Fixed regression caused by 🎫`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.

Fixes: #4361
Change-Id: I748549bc4c27fad6394593f8ec93fc22bfd01f6c
2018-11-09 23:22:22 -05:00
mike bayer 07de512bf1 Merge "Implement SQLite ON CONFLICT for constraints" 2018-11-09 22:43:20 +00:00
Denis Kataev de804d7245 Implement SQLite ON CONFLICT for constraints
Implemented the SQLite ``ON CONFLICT`` clause as understood at the DDL
level, e.g. for primary key, unique, and CHECK constraints as well as
specified on a :class:`.Column` to satisfy inline primary key and NOT NULL.
Pull request courtesy Denis Kataev.

Fixes: #4360
Change-Id: I4cd4bafa8fca41e3101c87dbbfe169741bbda3f4
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/431
2018-11-07 18:26:40 -05:00
Mike Bayer 1f13c8c833 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.

Change-Id: Id99894bb62cc506e896c9aa7c256e9f6e602243e
2018-11-06 15:13:03 -05:00
Mike Bayer 15ac07f7b6 Merge remote-tracking branch 'origin/pr/486'
Change-Id: I90596d4fc238b913146906db0ab700dd767c5615
2018-11-03 12:45:31 -04:00
Mike Bayer b4e4325a7c Merge remote-tracking branch 'origin/pr/450'
Change-Id: I50c0dd75199a34f68f9a2fa0f89208a887193969
2018-11-03 12:37:19 -04:00
mike bayer 4811e35fa3 Merge "Deannotate ORM columns in ColumnEntity" 2018-11-03 16:17:04 +00:00
Mike Bayer 88bfa1b89c 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.

Fixes: #4347
Change-Id: I191d4d1b1623898060a9accdfd186de16f89a6b7
2018-11-02 16:40:59 -04:00
Iwo Herka 9a29ae2267 Tweak code-style and readability in events/base.py
This includes a few low-key, syntax-level tweaks and:

1. Rewrite of the if-statment in `Events._accept_with`.
2. Property name change, i.e. from `dispatcher.dispatch_cls` to
`dispatcher.dispatch`. In this case postfix `_cls` is confusing as
the property is not a class, but an instance of one.
2018-11-02 19:06:25 +01:00
Mike Bayer bc04e63475 Add new NO_RAISE attribute flag and specify for m2o history load
Added new behavior to the lazy load that takes place when the "old" value of
a many-to-one is retrieved, such that exceptions which would be raised due
to either ``lazy="raise"`` or a detached session error are skipped.

Fixes: #4353
Change-Id: I6c6c77613e93061a909f5062b70b17e8913fc9ee
2018-11-02 09:23:24 -04:00
mike bayer bc7c212370 Merge "Implement __delete__" 2018-11-02 13:21:15 +00:00
Mike Bayer 2e2af8d918 Implement __delete__
A long-standing oversight in the ORM, the ``__delete__`` method for a many-
to-one relationship was non-functional, e.g. for an operation such as ``del
a.b``.  This is now implemented and is equivalent to setting the attribute
to ``None``.

Fixes: #4354
Change-Id: I60131a84c007b0bf6f20c5cc5f21a3b96e954046
2018-11-02 01:22:41 -04:00
Mike Bayer e991684a39 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
🎫`.3849`, where testing was insufficient to catch this additional
flaw.

Fixes: #4357
Change-Id: Iead058c0465dfa31c5b8a8780769278b7000acc8
2018-11-01 21:54:10 -04:00
Chris Macklin 1c3b2d7186 Add missing index method to _AssociationList.
Added missing ``.index()`` method to list-based association collections
in the association proxy extension.

Change-Id: Ice81dc4bcccd520638c5bc9a0f8bb2027946c846
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/485
2018-10-31 11:29:26 -04:00
mike bayer abb12a9d81 Merge "Move pk on single-inh subclass check below conflict resolution check" 2018-10-31 15:24:55 +00:00
mike bayer 4c487b9477 Merge "Add reserved word 'function' for MySQL" 2018-10-30 21:23:49 +00:00
Tom Manderson 3ed79a5c18 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.

Fixes: #4352
Change-Id: Id4c025da53c28e58db6b549fe398f25f8a90d355
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/483
2018-10-30 13:21:52 -04:00
Alex Hall 38c81328e9 Add reserved word 'function' for MySQL
Added word ``function`` to the list of reserved words for MySQL, which is
now a keyword in MySQL 8.0

Fixes: #4348
Change-Id: Idd30acda7e99076810f65d0ee860055a18dc9193
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/481
2018-10-30 13:12:13 -04:00
wodim f041f1d198 Add missing space 2018-10-30 13:04:36 -04:00
David Poggi 83864ffe63 re-word recycle parameter documentation
Change-Id: I80cabcd9fa3f3b45e5355bf6c774a8eee02e7f1b
2018-10-30 13:02:45 -04:00
Mike Bayer 65af4fc74a Merge remote-tracking branch 'origin/pr/478'
Change-Id: I0f27b6426dbfd665edf2a119b1cfaadb54511dd0
2018-10-30 12:53:42 -04:00