summaryrefslogtreecommitdiff
path: root/test/orm
Commit message (Collapse)AuthorAgeFilesLines
* Warn instead of raise for unmapped column that matches on keyticket_4073Mike Bayer2017-09-101-3/+19
| | | | | | | | | | | | | | | 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-081-25/+0
| | | | | | | | | | | | | | | 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 "Check for non-mapped property in synonym"mike bayer2017-09-051-0/+25
|\
| * Check for non-mapped property in synonymMike Bayer2017-09-041-0/+25
| | | | | | | | | | | | | | | | | | | | 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-1/+62
|/ | | | | | | | | | | | 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-0/+36
| | | | | | | | | | | | 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)
* Add SQL Server CI coverageMike Bayer2017-08-3113-41/+42
| | | | Change-Id: Ida0d01ae9bcc0573b86e24fddea620a38c962822
* Additional fixes to sane rowcountMike Bayer2017-08-314-26/+51
| | | | | | | | Implement rowcount assertions and single row check for post_update as well as deletes. Change-Id: I4e5ba7e8747bf0e0b41f569089eb8cdbf064b7a9 Fixes: #4062
* Ensure col is not None when retrieving quick populatorsMike Bayer2017-08-231-1/+124
| | | | | | | | | | | | | | | | 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-222-0/+67
| | | | | | | | | | 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-1/+107
| | | | | | | | | | | | 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
* - ensure identifier re-use doesn't make this breakMike Bayer2017-08-221-3/+4
| | | | Change-Id: I9fe6c42c097d31b50a479250d39a3cd8ebcbffaf
* Enable multi-level selectin polymorphic loadingMike Bayer2017-08-072-13/+342
| | | | | Change-Id: Icc742bbeecdb7448ce84caccd63e086af16e81c1 Fixes: #4026
* - fix one test for STRICT, which may be turned on by defaultMike Bayer2017-08-041-1/+2
| | | | | | in mariadb 10.2. more mariadb fixes coming Change-Id: I6e3a94ae7340772663677b1082506adbb2d84a38
* Merge "Check for column object in eval_none, not propkey"mike bayer2017-07-191-5/+44
|\
| * Check for column object in eval_none, not propkeyMike Bayer2017-07-181-5/+44
| | | | | | | | | | | | | | | | | | | | 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/+19
|/ | | | | | | | | | 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
* Support state expiration for with_expression(); rename deferred_expressionMike Bayer2017-06-261-4/+51
| | | | | | | | | | | | | | | 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-191-1/+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-0/+136
|\
| * Add all versioning logic to _post_update()Mike Bayer2017-06-151-0/+136
| | | | | | | | | | | | | | | | | | | | 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-162-4/+91
|/ | | | | | | | | | | | | | | | | | | | | | | 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
* - remove redundant fixture from base test classMike Bayer2017-06-151-15/+0
| | | | Change-Id: I76f197d5b2b39ae476bfff924e899773aa123be0
* - ensure String has a length for mysql compatibilityMike Bayer2017-06-151-1/+1
| | | | Change-Id: Iaa1077ca5929bdc67300cc6bfb1ba98aff382246
* Repair regression to pathing for subclassesMike Bayer2017-06-151-1/+65
| | | | | | | | | 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
* - assert passive_deletes='all' does not affect collection/scalarMike Bayer2017-06-061-20/+25
| | | | | | | | | | | | 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-0/+16
| | | | | | | | | | | 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-1/+68
| | | | | | | | | | | | 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-051-0/+260
| | | | | | | | | | | | | 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
* Flatten operator precedence for comparison operatorsMichael Birtwell2017-05-251-5/+5
| | | | | | | | | | | | | | | The operator precedence for all comparison operators such as LIKE, IS, IN, MATCH, equals, greater than, less than, etc. has all been merged into one level, so that expressions which make use of these against each other will produce parentheses between them. This suits the stated operator precedence of databases like Oracle, MySQL and others which place all of these operators as equal precedence, as well as Postgresql as of 9.5 which has also flattened its operator precendence. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #3999 Change-Id: I3f3d5124a64af0d376361cdf15a97e2e703be56f Pull-request: https://github.com/zzzeek/sqlalchemy/pull/367
* Add with_for_update() support in session.refresh()Mike Bayer2017-05-242-1/+98
| | | | | | | | | | | | | | | 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-231-0/+17
| | | | | | | | | | 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-231-1/+53
| | | | | | | | | | | | 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/+73
| | | | | | | | | 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/+62
| | | | | | | | | | | | | | 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-0/+23
| | | | | | | | | 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
* Merge "Demote innerjoin to outerjoin coming from with_polymorphic"mike bayer2017-05-121-0/+52
|\
| * Demote innerjoin to outerjoin coming from with_polymorphicMike Bayer2017-05-121-0/+52
| | | | | | | | | | | | | | | | | | | | | | 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-0/+139
|/ | | | | | | | | | | | | | | 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
* Add conditionals specific to deferred for expire ro propertiesMike Bayer2017-05-101-2/+51
| | | | | | | | | | 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
* Add selectin loadingMike Bayer2017-04-262-2/+1986
| | | | | | | | | | Adding a new kind of relationship loader that is a cross between the "immediateload" and the "subquery" eager loader, using an IN criteria to load related items in bulk immediately after the lead query result is loaded. Change-Id: If13713fba9b465865aef8fd50b5b6b977fe3ef7d Fixes: #3944
* Accommodate for query._current_path in subq eager load join_depthMike Bayer2017-04-171-2/+35
| | | | | | | | | | Fixed bug in subquery eager loading where the "join_depth" parameter for self-referential relationships would not be correctly honored, loading all available levels deep rather than correctly counting the specified number of levels for eager loading. Change-Id: Ifa54085cbab3b41c2196f3ee519f485c63e4cb8d Fixes: #3967
* Use baked lazyloading by defaultMike Bayer2017-04-131-3/+396
| | | | | | | | | | | | | The ``lazy="select"`` loader strategy now makes used of the :class:`.BakedQuery` query caching system in all cases. This removes most overhead of generating a :class:`.Query` object and running it into a :func:`.select` and then string SQL statement from the process of lazy-loading related collections and objects. The "baked" lazy loader has also been improved such that it can now cache in most cases where query load options are used. Change-Id: Ic96792fffaa045ae9aa0a4657d6d29235d3efb85 Fixes: #3954
* Warn on _compiled_cache growthMike Bayer2017-04-121-0/+25
| | | | | | | | | | | | | | | | | Added warnings to the LRU "compiled cache" used by the :class:`.Mapper` (and ultimately will be for other ORM-based LRU caches) such that when the cache starts hitting its size limits, the application will emit a warning that this is a performance-degrading situation that may require attention. The LRU caches can reach their size limits primarily if an application is making use of an unbounded number of :class:`.Engine` objects, which is an antipattern. Otherwise, this may suggest an issue that should be brought to the SQLAlchemy developer's attention. Additionally, adjusted the test_memusage algorithm again as the previous one could still allow a growing memory size to be missed. Change-Id: I020d1ceafb7a08f6addfa990a1e7acd09f933240
* Compare entities also on chop_pathMike Bayer2017-04-102-0/+207
| | | | | | | | | | | | | | | | | When comparing query._current_path to options, the path chop was not taking into account that the query or the options are against aliased classes that don't match the mapper. The issue does not seem to take place for the Load() version of _chop_path. Fixed bug to improve upon the specificity of loader options that take effect subsequent to the lazy load of a related entity, so that the loader options will match to an aliased or non-aliased entity more specifically if those options include entity information. Fixes: #3963 Change-Id: Ifdff37d579042fcc62bdeabce9e2413e9a03fbba
* Allow aliased() to be passed to Query.select_entity_from().Mike Bayer2017-03-271-0/+25
| | | | | | | | | | | | | | | | | An :func:`.aliased()` construct can now be passed to the :meth:`.Query.select_entity_from` method. Entities will be pulled from the selectable represented by the :func:`.aliased` construct. This allows special options for :func:`.aliased` such as :paramref:`.aliased.adapt_on_names` to be used in conjunction with :meth:`.Query.select_entity_from`. Additionally rewrote the docstring for :meth:`.Query.select_entity_from`, including starting with explicit use of :func:`.aliased` as the usual idiomatic pattern. An example using text().columns() is added as well as the use case from :ticket:`3933` using name matching. Change-Id: If7e182965236993064a2a086e3b6d55a4f097ca8 Fixes: #3933
* Treat collation names as identifiersMike Bayer2017-03-231-2/+2
| | | | | | | | | | | The expression used for COLLATE as rendered by the column-level :func:`.expression.collate` and :meth:`.ColumnOperators.collate` is now quoted as an identifier when the name is case sensitive, e.g. has uppercase characters. Note that this does not impact type-level collation, which is already quoted. Change-Id: I83d5d9cd1e66a4f20b96303bb84c5f360d5d6a1a Fixes: #3785
* Support hybrids/composites with bulk updatesMike Bayer2017-03-222-19/+54
| | | | | | | | | | | The :meth:`.Query.update` method can now accommodate both hybrid attributes as well as composite attributes as a source of the key to be placed in the SET clause. For hybrids, an additional decorator :meth:`.hybrid_property.update_expression` is supplied for which the user supplies a tuple-returning function. Change-Id: I15e97b02381d553f30b3301308155e19128d2cfb Fixes: #3229
* Raise on flag_modified() for non-present attributeMike Bayer2017-03-211-1/+38
| | | | | | | | | | | | The :func:`.attributes.flag_modified` function now raises :class:`.InvalidRequestError` if the named attribute key is not present within the object, as this is assumed to be present in the flush process. To mark an object "dirty" for a flush without referring to any specific attribute, the :func:`.attributes.flag_dirty` function may be used. Change-Id: I6c64e4d253c239e38632f38c27bb16e68fe8dfbe Fixes: #3753
* Add bulk_replace event, integrate with @validatesMike Bayer2017-03-161-0/+37
| | | | | | | | | | | | | | | | | | | | Added new attribute event :meth:`.AttributeEvents.bulk_replace`. This event is triggered when a collection is assigned to a relationship, before the incoming collection is compared with the existing one. This early event allows for conversion of incoming non-ORM objects as well. The event is integrated with the ``@validates`` decorator. The ``@validates`` decorator now allows the decorated method to receive objects from a "bulk collection set" operation that have not yet been compared to the existing collection. This allows incoming values to be converted to compatible ORM objects as is already allowed from an "append" event. Note that this means that the ``@validates`` method is called for **all** values during a collection assignment, rather than just the ones that are new. Change-Id: I27f59db008d9e521d31a3e30143d7cd997e4b7b3 Fixes: #3896