summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm
Commit message (Collapse)AuthorAgeFilesLines
* Don't use repr() for Column/ColumnClause in warningMike Bayer2017-09-101-2/+3
| | | | | | | | for #4073, use the string version of the column expression in the warning, otherwise the repr() is showing the hex id which causes unlimited warnings. Change-Id: I6869b685b237e7f02c7b5071701dd63a3577182a
* Warn instead of raise for unmapped column that matches on keyticket_4073Mike Bayer2017-09-102-7/+17
| | | | | | | | | | | | | | | Modified the change made to the ORM update/delete evaluator in :ticket:`3366` such that if an unmapped column expression is present in the update or delete, if the evaluator can match its name to the mapped columns of the target class, a warning is emitted, rather than raising UnevaluatableError. This is essentially the pre-1.2 behavior, and is to allow migration for applications that are currently relying upon this pattern. However, if the given attribute name cannot be matched to the columns of the mapper, the UnevaluatableError is still raised, which is what was fixed in :ticket:`3366`. Change-Id: I658ed0dbf485b7f8009774f9c12d9912447abd2a Fixes: #4073
* Remove LRU warningsMike Bayer2017-09-082-38/+3
| | | | | | | | | | | | | | | Removed the warnings that are emitted when the LRU caches employed by the mapper as well as loader srtategies reach their threshold; the purpose of this warning was at first a guard against excess cache keys being generated but became basically a check on the "creating many engines" antipattern. While this is still an antipattern, the presense of test suites which both create an engine per test as well as raise on all warnings will be an inconvenience; it should not be critical that such test suites change their architecture just for this warning (though engine-per-test suite is always better). Change-Id: I41ef8cd642d05a845f53119b196440f9d7879cd9 Fixes: #4071
* Merge "Guard against KeyError in session.merge after check for identity"mike bayer2017-09-051-18/+24
|\
| * Guard against KeyError in session.merge after check for identityMike Bayer2017-09-041-18/+24
| | | | | | | | | | | | | | | | | | | | Fixed bug in :meth:`.Session.merge` following along similar lines as that of :ticket:`4030`, where an internal check for a target object in the identity map could lead to an error if it were to be garbage collected immediately before the merge routine actually retrieves the object. Change-Id: Ifecfb8b9d50c52d0ebd5a03e1bd69fe3abf1dc40 Fixes: #4069
* | Merge "Check for non-mapped property in synonym"mike bayer2017-09-051-1/+12
|\ \
| * | Check for non-mapped property in synonymMike Bayer2017-09-041-1/+12
| |/ | | | | | | | | | | | | | | | | | | An :class:`.InvalidRequestError` is raised when a :func:`.synonym` is used against an attribute that is not against a :class:`.MapperProperty`, such as an association proxy. Previously, a recursion overflow would occur trying to locate non-existent attributes. Change-Id: If2ce38c429a69951df4c94b71b74edbd59d775e3 Fixes: #4067
* | Always check that discarded state is the expected oneMike Bayer2017-09-041-11/+22
|/ | | | | | | | | | | | Fixed race condition in ORM identity map which would cause objects to be inappropriately removed during a load operation, causing duplicate object identities to occur, particularly under joined eager loading which involves deduplication of objects. The issue is specific to garbage collection of weak references and is observed only under the Pypy interpreter. Change-Id: I9f6ae3fe5b078f26146af82b15d16f3a549a9032 Fixes: #4068
* Consider merge key with (None, ) as non-persistentMike Bayer2017-08-311-5/+5
| | | | | | | | | | | | Fixed bug in :meth:`.Session.merge` where objects in a collection that had the primary key attribute set to ``None`` for a key that is typically autoincrementing would be considered to be a database-persisted key for part of the internal deduplication process, causing only one object to actually be inserted in the database. Change-Id: I0a6e00043be0b2979cda33740e1be3b430ecf8c7 Fixes: #4056 (cherry picked from commit 5243341ed886e10a0d3f7fef8ae3d071e0ffdcf0)
* Additional fixes to sane rowcountMike Bayer2017-08-311-2/+12
| | | | | | | | Implement rowcount assertions and single row check for post_update as well as deletes. Change-Id: I4e5ba7e8747bf0e0b41f569089eb8cdbf064b7a9 Fixes: #4062
* Add new sane_rowcount_w_returning flagMike Bayer2017-08-311-9/+15
| | | | | | | | | | | | | | | | | Added a new class of "rowcount support" for dialects that is specific to when "RETURNING", which on SQL Server looks like "OUTPUT inserted", is in use, as the PyODBC backend isn't able to give us rowcount on an UPDATE or DELETE statement when OUTPUT is in effect. This primarily affects the ORM when a flush is updating a row that contains server-calcluated values, raising an error if the backend does not return the expected row count. PyODBC now states that it supports rowcount except if OUTPUT.inserted is present, which is taken into account by the ORM during a flush as to whether it will look for a rowcount. ORM tests are implicit in existing tests run against PyODBC Fixes: #4062 Change-Id: Iff17cbe4c7a5742971ed85a4d58660c18cc569c2
* Ensure col is not None when retrieving quick populatorsMike Bayer2017-08-231-2/+17
| | | | | | | | | | | | | | | | Fixed bug where an :func:`.undefer_group` option would not be recognized if it extended from a relationship that was loading using joined eager loading. In particular we need to double check the column both in terms of the given "adapter" as well as without applying the "adapter" when searching for the column in the result. As we now avoid redoing the row processor step we also improve on callcounts in joined eager loading. Change-Id: I0f48766f12f7299f4626ff41a00bf1f5bfca5f3b Fixes: #4048
* Handle cache key for option that has no strategyMike Bayer2017-08-221-1/+1
| | | | | | | | | | Fixed regression where the use of a :func:`.undefer_group` option in conjunction with a lazy loaded relationship option would cause an attribute error, due to a bug in the SQL cache key generation added in 1.2 as part of :ticket:`3954`. Change-Id: Icd9a34f0b5aa96d6433a2ab9c8d3eaee0006f609 Fixes: #4049
* Deactivate transaction if rollback failsMike Bayer2017-08-221-0/+1
| | | | | | | | | | | | Fixed regression introduced in 1.2.0b1 due to :ticket:`3934` where the :class:`.Session` would fail to "deactivate" the transaction, if a rollback failed (the target issue is when MySQL loses track of a SAVEPOINT). This would cause a subsequent call to :meth:`.Session.rollback` to raise an error a second time, rather than completing and bringing the :class:`.Session` back to ACTIVE. Fixes: #4050 Change-Id: Id245e8dd3487cb006b2d6631c8bd513b5ce81abe
* Merge branch 'master--typos' of https://github.com/nphilipp/sqlalchemyMike Bayer2017-08-091-2/+2
|\
| * fix "constrast" typosNils Philippsen2017-08-051-2/+2
| |
* | Enable multi-level selectin polymorphic loadingMike Bayer2017-08-076-36/+104
| | | | | | | | | | Change-Id: Icc742bbeecdb7448ce84caccd63e086af16e81c1 Fixes: #4026
* | - modernize orm.reconstructor documentation a bitMike Bayer2017-08-052-0/+11
|/ | | | Change-Id: Ied786e8f9ad78f524be03a382d002dada7dd218b
* Guard all indexed access in WeakInstanceDictMike Bayer2017-07-241-15/+38
| | | | | | | | | | | | Added ``KeyError`` checks to all methods within :class:`.WeakInstanceDict` where a check for ``key in dict`` is followed by indexed access to that key, to guard against a race against garbage collection that under load can remove the key from the dict after the code assumes its present, leading to very infrequent ``KeyError`` raises. Change-Id: I881cc2899f7961d29a0549f44149a2615ae7a4ea Fixes: #4030
* Merge "Check for column object in eval_none, not propkey"mike bayer2017-07-192-2/+2
|\
| * Check for column object in eval_none, not propkeyMike Bayer2017-07-182-2/+2
| | | | | | | | | | | | | | | | | | | | Fixed bug involving JSON NULL evaluation logic added in 1.1 as part of :ticket:`3514` where the logic would not accommodate ORM mapped attributes named differently from the :class:`.Column` that was mapped. Change-Id: I1848afcfb63ad7f074f315d8d3097666069b42be Fixes: #4031
* | Check for non-entity when inspecting for subqueryloadMike Bayer2017-07-181-0/+1
|/ | | | | | | | | | Fixed issue where adding additional non-entity columns to a query that includes an entity with subqueryload relationships would fail, due to an inspection added in 1.1.11 as a result of :ticket:`4011`. Change-Id: I8ef082be649125bdc07b428cb9b0a77a65d73671 Fixes: #4033
* Add .autocommit to scoped_sessionBen Fagin2017-07-051-1/+2
| | | | | | | | | | Added ``.autocommit`` attribute to :class:`.scoped_session`, proxying the ``.autocommit`` attribute of the underling :class:`.Session` currently assigned to the thread. Pull request courtesy Ben Fagin. Change-Id: Iff741978bd67762f4c7375a23cc151b26192042b Pull-request: https://github.com/zzzeek/sqlalchemy/pull/372
* Support state expiration for with_expression(); rename deferred_expressionMike Bayer2017-06-265-13/+27
| | | | | | | | | | | | | | | The attributeimpl for a deferred_expression does not support a scalar loader, add new configurability so that the impl can have this flag turned off. Document that the with_expression() system currently does not offer any deferred loading. To eliminate confusion over "deferred", which refers to lazy loading of column attributes, and "with_expression", which refers to an attribute that is explicitly at query time only, rename deferred_expression to query_expression. Change-Id: I07c4a050ed68c79ccbde9492e9de1630b7470d74
* Add ad-hoc mapped expressionsMike Bayer2017-06-193-0/+106
| | | | | | | | | | Added a new feature :func:`.orm.with_expression` that allows an ad-hoc SQL expression to be added to a specific entity in a query at result time. This is an alternative to the SQL expression being delivered as a separate element in the result tuple. Change-Id: Id8c479f7489fb02e09427837c59d1eabb2a6c014 Fixes: #3058
* Merge "Add all versioning logic to _post_update()"mike bayer2017-06-161-17/+93
|\
| * Add all versioning logic to _post_update()Mike Bayer2017-06-151-17/+93
| | | | | | | | | | | | | | | | | | | | An UPDATE emitted as a result of the :paramref:`.relationship.post_update` feature will now integrate with the versioning feature to both bump the version id of the row as well as assert that the existing version number was matched. Fixes: #3496 Change-Id: I865405dd6069f1c1e3b0d27a4980e9374e059f97
* | Set complete FROM list for subquery eagerload's orig queryMike Bayer2017-06-161-8/+15
|/ | | | | | | | | | | | | | | | | | | | | | | Instead of checking that the "orig_entity" we receive applies as a correct FROM element for the subquery we're building, set the FROM clause of the query to exactly what it already is based on column_descriptions (assuming there is no FROM list already), thereby ensuring that the FROM list will remain intact, regardless of what orig_entity turns out to be and what the target_cols ultimately refer towards. Fixed issue with subquery eagerloading which continues on from the series of issues fixed in :ticket:`2699`, :ticket:`3106`, :ticket:`3893` involving that the "subquery" contains the correct FROM clause when beginning from a joined inheritance subclass and then subquery eager loading onto a relationship from the base class, while the query also includes criteria against the subclass. The fix in the previous tickets did not accommodate for additional subqueryload operations loading more deeply from the first level, so the fix has been further generalized. Change-Id: Ic909590814f71e577d8266b1dbc4c393dc48e019 Fixes: #4011
* Repair regression to pathing for subclassesMike Bayer2017-06-151-2/+7
| | | | | | | | | Issue #3963's initial commit narrowed the "current path" match rules too much such that a path that matches current path on subclass would no longer match. Change-Id: I8c9a0db91a09d789cfb8666288a913f8bbcdb2e9 Fixes: #3963
* Refinements for unitofwork internalsMike Bayer2017-06-142-51/+66
| | | | | | | | | | | * remove "mapper" argument from SaveUpdateState, DeleteState * use __slots__ for all uow action classes * rename ".delete" to ".isdelete" * rename issue_post_update to register_post_update since this doesn't actually issue the UPDATE * rename IssuePostUpdate to PostUpdateAll Change-Id: Ia6263b80d6a86eab1e8ed38df1421b1d0f249797
* - assert passive_deletes='all' does not affect collection/scalarMike Bayer2017-06-061-7/+8
| | | | | | | | | | | | membership removal in issue #3844 we hypotheized that passive_deletes='all' was broken because it sets to NULL a foreign key attribute when the child object is removed or replaced. However, not doing the NULL set means that nothing happens at all and the operation silently fails. Change-Id: I11834e7e324349e172dc797bac62731008b6b95a
* Re-send column value w/ onupdate default during post-updateMike Bayer2017-06-061-1/+1
| | | | | | | | | | | Adjusted the behavior of post_update such that if a column with an "onupdate" default has received an explicit value for INSERT, re-send the same data during a post-update UPDATE so that the value remains in effect, rather than an onupdate overwriting it. Change-Id: I26bccb6f957dcad07a2bcbda2dd9e14c60b92b06 Fixes: #3471
* Implement _postfetch_post_update to expire/refresh onupdates in post_updateMike Bayer2017-06-051-5/+39
| | | | | | | | | | | | Fixed bug involving the :paramref:`.relationship.post_update` feature where a column "onupdate" value would not result in expiration or refresh of the corresponding object attribute, if the UPDATE for the row were a result of the "post update" feature. Additionally, the :meth:`.SessionEvents.refresh_flush` event is now emitted for these attributes when refreshed within the flush. Fixes: #3472 Change-Id: I5ee2d715e773a306ab1e8143e4382c228991ac78
* selectin polymorphic loadingMike Bayer2017-06-056-18/+295
| | | | | | | | | | | | | Added a new style of mapper-level inheritance loading "polymorphic selectin". This style of loading emits queries for each subclass in an inheritance hierarchy subsequent to the load of the base object type, using IN to specify the desired primary key values. Fixes: #3948 Change-Id: I59e071c6142354a3f95730046e3dcdfc0e2c4de5
* Add with_for_update() support in session.refresh()Mike Bayer2017-05-242-5/+33
| | | | | | | | | | | | | | | Session.refresh() is still hardcoded to legacy lockmode, come up with a new API so that the newer argument style works with it. Added new argument :paramref:`.with_for_update` to the :meth:`.Session.refresh` method. When the :meth:`.Query.with_lockmode` method were deprecated in favor of :meth:`.Query.with_for_update`, the :meth:`.Session.refresh` method was never updated to reflect the new option. Change-Id: Ia02a653746b7024699b515451525a88d7a17d63a Fixes: #3991
* Add AttributeEvents.modifiedMike Bayer2017-05-232-6/+37
| | | | | | | | | | Added new event handler :meth:`.AttributeEvents.modified` which is triggered when the func:`.attributes.flag_modified` function is invoked, which is common when using the :mod:`sqlalchemy.ext.mutable` extension module. Change-Id: Ic152f1d5c53087d780b24ed7f1f1571527b9e8fc Fixes: #3303
* Add clause adaptation for AliasedClass to with_parent()Mike Bayer2017-05-233-16/+36
| | | | | | | | | | | | Fixed bug where :meth:`.Query.with_parent` would not work if the :class:`.Query` were against an :func:`.aliased` construct rather than a regular mapped class. Also adds a new parameter :paramref:`.util.with_parent.from_entity` to the standalone :func:`.util.with_parent` function as well as :meth:`.Query.with_parent`. Change-Id: Ic684dd63cc90b582c7580c9bba3c92fa3f286da7 Fixes: #3607
* detect and raise for version_id is NULLDiana Clarke2017-05-221-0/+5
| | | | | | | | | The versioning feature does not support NULL for the version counter. An exception is now raised if the version id is programmatic and was set to NULL for an UPDATE. Pull request courtesy Diana Clarke. Fixes: #3673 Change-Id: I8b0da56234a7c7f5e7fde35536e09a6216a5e48a
* Detect no params w/ manual version_id counter and set to itselfMike Bayer2017-05-221-0/+7
| | | | | | | | | | | | | | Fixed bug where programmatic version_id counter in conjunction with joined table inheritance would fail if the version_id counter were not actually incremented and no other values on the base table were modified, as the UPDATE would have an empty SET clause. Since programmatic version_id where version counter is not incremented is a documented use case, this specific condition is now detected and the UPDATE now sets the version_id value to itself, so that concurrency checks still take place. Change-Id: I80e385bffeed4851cc20131cbe983c173a46f655 Fixes: #3996
* Remove "scope" keyword from scoped_session.__call__()Mike Bayer2017-05-221-11/+7
| | | | | | | | | Removed a very old keyword argument from :class:`.scoped_session` called ``scope``. This keyword was never documented and was an early attempt at allowing for variable scopes. Change-Id: I9a26498a1a66d1eafb0723e98b527688a60f9d9b Fixes: #3796
* Add new configuration, inspection for baked queriesMike Bayer2017-05-171-0/+17
| | | | | | | | | | Added new flag :paramref:`.Session.enable_baked_queries` to the :class:`.Session` to allow baked queries to be disabled session-wide, reducing memory use. Also added new :class:`.Bakery` wrapper so that the bakery returned by :paramref:`.BakedQuery.bakery` can be inspected. Change-Id: I5657af7a99d2b24c89d6aee1343f432728e3f807
* - add complete parameter /return value docs to session.begin() /Mike Bayer2017-05-171-13/+45
| | | | | | session.begin_nested(). Fixes #3993 Change-Id: If485d77b364c34d94061d2f48efbde3f8a8adec9
* - give SelectinLoader its own bakery, dont use mapperMike Bayer2017-05-161-8/+22
| | | | | | | | level cache - include SelectinLoader itself in the cache key, though this is currently not critical Change-Id: I8e4bcd579277fbe53d9c7eca3552a0b8ab9d7a39
* Merge "Demote innerjoin to outerjoin coming from with_polymorphic"mike bayer2017-05-124-9/+23
|\
| * Demote innerjoin to outerjoin coming from with_polymorphicMike Bayer2017-05-124-9/+23
| | | | | | | | | | | | | | | | | | | | | | a with_polymorphic, regardless of inheritance type, represents multiple classes. A subclass that wants to joinedload with innerjoin=True needs to be demoted to an outerjoin because the parent entity rows might not be of that type. Looks more intuitive with a joined inheritance load, but applies just as well to single or concrete. Change-Id: I4d3d76106ae20032269f8848aad70a8e2f9422f9 Fixes: #3988
* | Cascade mappers in terms of the instance's mapperMike Bayer2017-05-121-4/+10
|/ | | | | | | | | | | | | | | Fixed a (extremely old) bug in cascade_mappers where the first cascade we do is against the "self" mapper, and not the one that actually corresponds to the state given. These are different in the case where we start with a relationship to a class, and the instance is of a subclass, which itself can have relationships that aren't on the base mapper. A pretty severe bug that somehow has avoided the radar since the beginning. Change-Id: I512956b9757b07e06f3ca1ccb507a33fb10bed31 Fixes: #3986
* Merge "Update inheritance documentation."mike bayer2017-05-101-6/+4
|\
| * Update inheritance documentation.Mike Bayer2017-05-101-6/+4
| | | | | | | | | | | | | | | | The inheritance documentation is confused, disorganized, and out of date. Reorganize and clarify, in particular in preparation for new inheritance features. Change-Id: Ibe6a35b4b0432bad866a6afb0598b2cf1b509f10
* | Add conditionals specific to deferred for expire ro propertiesMike Bayer2017-05-101-2/+10
| | | | | | | | | | | | | | | | | | | | Fixed bug where a :func:`.column_property` that is also marked as "deferred" would be marked as "expired" during a flush, causing it to be loaded along with the unexpiry of regular attributes even though this attribute was never accessed. Change-Id: Iaa9e17b66ece30a8e729e4af746b31ff99b1ec9a Fixes: #3984
* | fixes a typoBen Fagin2017-05-011-1/+1
|/