summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Don't run pending_to_persistent for non-new objectsMike Bayer2019-02-091-2/+12
| | | | | | | | | | | Fixed fairly simple but critical issue where the :meth:`.SessionEvents.pending_to_persistent` event would be invoked for objects not just when they move from pending to persistent, but when they were also already persistent and just being updated, thus causing the event to be invoked for all objects on every update. Fixes: #4489 Change-Id: Ibe147020aa62f7d605cb1029b7f3b776f42e6b43
* Remove all remaining text() coercions and ensure identifiers are safeMike Bayer2019-02-061-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fully removed the behavior of strings passed directly as components of a :func:`.select` or :class:`.Query` object being coerced to :func:`.text` constructs automatically; the warning that has been emitted is now an ArgumentError or in the case of order_by() / group_by() a CompileError. This has emitted a warning since version 1.0 however its presence continues to create concerns for the potential of mis-use of this behavior. Note that public CVEs have been posted for order_by() / group_by() which are resolved by this commit: CVE-2019-7164 CVE-2019-7548 Added "SQL phrase validation" to key DDL phrases that are accepted as plain strings, including :paramref:`.ForeignKeyConstraint.on_delete`, :paramref:`.ForeignKeyConstraint.on_update`, :paramref:`.ExcludeConstraint.using`, :paramref:`.ForeignKeyConstraint.initially`, for areas where a series of SQL keywords only are expected.Any non-space characters that suggest the phrase would need to be quoted will raise a :class:`.CompileError`. This change is related to the series of changes committed as part of :ticket:`4481`. Fixed issue where using an uppercase name for an index type (e.g. GIST, BTREE, etc. ) or an EXCLUDE constraint would treat it as an identifier to be quoted, rather than rendering it as is. The new behavior converts these types to lowercase and ensures they contain only valid SQL characters. Quoting is applied to :class:`.Function` names, those which are usually but not necessarily generated from the :attr:`.sql.func` construct, at compile time if they contain illegal characters, such as spaces or punctuation. The names are as before treated as case insensitive however, meaning if the names contain uppercase or mixed case characters, that alone does not trigger quoting. The case insensitivity is currently maintained for backwards compatibility. Fixes: #4481 Fixes: #4473 Fixes: #4467 Change-Id: Ib22a27d62930e24702e2f0f7c74a0473385a08eb
* Fix many spell glitchesLele Gaifax2019-01-251-2/+2
| | | | | | | | | | | | This affects mostly docstrings, except in orm/events.py::dispose_collection() where one parameter gets renamed: given that the method is empty, it seemed reasonable to me to fix that too. Closes: #4440 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4440 Pull-request-sha: 779ed75acb6142e1f1daac467b5b14134529bb4b Change-Id: Ic0553fe97853054b09c2453af76d96363de6eb0e
* Implement relationship to AliasedClass; deprecate non primary mappersMike Bayer2019-01-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Implemented a new feature whereby the :class:`.AliasedClass` construct can now be used as the target of a :func:`.relationship`. This allows the concept of "non primary mappers" to no longer be necessary, as the :class:`.AliasedClass` is much easier to configure and automatically inherits all the relationships of the mapped class, as well as preserves the ability for loader options to work normally. - introduce new name for mapped_table, "persist_selectable". this is the selectable that selects against the local mapper and its superclasses, but does not include columns local only to subclasses. - relationship gains "entity" which is the mapper or aliasedinsp. - clarfiy name "entity" vs. "query_entity" in loader strategies. Fixes: #4423 Fixes: #4422 Fixes: #4421 Fixes: #3348 Change-Id: Ic3609b43dc4ed115006da9ad9189e574dc0c72d9
* Add deprecation warnings to all deprecated APIsMike Bayer2019-01-231-43/+44
| | | | | | | | | | | | | | | A large change throughout the library has ensured that all objects, parameters, and behaviors which have been noted as deprecated or legacy now emit ``DeprecationWarning`` warnings when invoked. As the Python 3 interpreter now defaults to displaying deprecation warnings, as well as that modern test suites based on tools like tox and pytest tend to display deprecation warnings, this change should make it easier to note what API features are obsolete. See the notes added to the changelog and migration notes for further details. Fixes: #4393 Change-Id: If0ea11a1fc24f9a8029352eeadfc49a7a54c0a1b
* Remove version directives for 0.6, 0.7, 0.8Mike Bayer2019-01-151-17/+3
| | | | | | | | | - fix a few "seealso"s - ComparableProprerty's "superseded in 0.7" becomes deprecated in 0.7 Backport to currently maintained doc versions 1.2, 1.1 Change-Id: Ib1fcb2df8673dbe5c4ffc47f3896a60d1dfcb4b2
* Merge "Add standalone orm.close_all method and deprecate SessionMaker.close_all"mike bayer2019-01-131-2/+25
|\
| * Add standalone orm.close_all method and deprecate SessionMaker.close_allAugustin Trancart2019-01-121-2/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added a new function :func:`.close_all_sessions` which takes over the task of the :meth:`.Session.close_all` method, which is now deprecated as this is confusing as a classmethod. Pull request courtesy Augustin Trancart. Fixes: #4412 Closes: #4438 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4438 Pull-request-sha: 7833d12a9898c82d50716427144bf3276c22ab3f Change-Id: Ib35eaa520ae886f3f8f550f9712fc3b139e00b60
* | Merge "use ..deprecated directive w/ version in all cases"mike bayer2019-01-121-13/+29
|\ \ | |/ |/|
| * use ..deprecated directive w/ version in all casesMike Bayer2019-01-111-13/+29
| | | | | | | | | | | | | | | | | | These changes should be ported from 1.3 back to 1.0 or possibly 0.9 to the extent they are relevant in each version. In 1.3 we hope to turn all deprecation documentation into warnings. Change-Id: I205186cde161af9389af513a425c62ce90dd54d8
* | happy new yearMike Bayer2019-01-111-1/+1
|/ | | | Change-Id: I6a71f4924d046cf306961c58dffccf21e9c03911
* Post black reformattingMike Bayer2019-01-061-22/+31
| | | | | | | | | | | | | Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
* Run black -l 79 against all source filesMike Bayer2019-01-061-209/+361
| | | | | | | | | | | | | | This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
* Improve documentation re: Session.binds and partitioning strategiesMike Bayer2018-11-061-21/+80
| | | | | | | | | 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
* Add test and retroactive changelog for issue 4040Mike Bayer2018-10-011-1/+2
| | | | | Fixes: #4040 Change-Id: I707c1cd2708a37102ad8184bec21be35cb6242d7
* Add option to sort into inserts/updates to bulk_save_objectsAlessandro Cucci2018-08-271-3/+17
| | | | | | | | | | | Added new flag :paramref:`.Session.bulk_save_objects.preserve_order` to the :meth:`.Session.bulk_save_objects` method, which defaults to True. When set to False, the given mappings will be grouped into inserts and updates per each object type, to allow for greater opportunities to batch common operations together. Pull request courtesy Alessandro Cucci. Change-Id: I0d041f7696cf733655a74beeceee3fa80640efd7 Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/6
* - add some seealsos for the transient object that loads use caseMike Bayer2018-03-021-0/+11
| | | | | Change-Id: Ibfa79a3721f31806223906cccf4547673b3d42f1 (cherry picked from commit 5de2e17b6e6686adf0a87038e90b001978187c0a)
* Fix enable_relationship_loading() works fine w/ one-to-manyMike Bayer2018-03-021-3/+5
| | | | Change-Id: I6efb62afa02be4d42482cfdbec739a5c6ab32bd7
* happy new yearMike Bayer2018-01-121-1/+1
| | | | Change-Id: I3ef36bfd0cb0ba62b3123c8cf92370a43156cf8f
* Check for object was expunged before restoring after pk switch + rollbackMike Bayer2018-01-041-4/+10
| | | | | | | | | | Fixed bug where an object that is expunged during a rollback of a nested or subtransaction which also had its primary key mutated would not be correctly removed from the session, causing subsequent issues in using the session. Change-Id: I57e2888902015d67ee11857e44382818f1d2f8bc Fixes: #4151
* Fix as many RST parse warnings as possible.Mike Bayer2017-11-031-10/+10
| | | | | | | Still a few I can't get. Also 0.9 is EOL so hide the unreleased notes. Change-Id: If0e44d4a0b3e78e211f32d5c33b51b1a007c9c69
* Add missing space in repr of the sessionmaker classPaul Anton Letnes2017-10-161-1/+1
| | | The missing space was driving me nuts.
* - add more dragons to session.begin() / autocommit docsMike Bayer2017-09-281-11/+26
| | | | Change-Id: I9e326f353d396321565dfbf53b7a30f18d8c86e9
* Don't expire "deferred" attributes in make_transient_to_detachedMike Bayer2017-09-261-1/+1
| | | | | | | | | | Fixed issue where the :func:`.make_transient_to_detached` function would expire all attributes on the target object, including "deferred" attributes, which has the effect of the attribute being undeferred for the next refesh, causing an unexpected load of the attribute. Change-Id: I82a385e3033e3f3c31569b1e908efb5f258d0f27 Fixes: #4084
* 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
* 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)
* 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
* Enable multi-level selectin polymorphic loadingMike Bayer2017-08-071-5/+13
| | | | | Change-Id: Icc742bbeecdb7448ce84caccd63e086af16e81c1 Fixes: #4026
* Add with_for_update() support in session.refresh()Mike Bayer2017-05-241-2/+29
| | | | | | | | | | | | | | | 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 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
* fixes a typoBen Fagin2017-05-011-1/+1
|
* Emit after_rollback() event before snapshot removalMike Bayer2017-03-141-14/+12
| | | | | | | | | | | | The state of the :class:`.Session` is now present when the :meth:`.SessionEvents.after_rollback` event is emitted, that is, the attribute state of objects prior to their being expired. This is now consistent with the behavior of the :meth:`.SessionEvents.after_commit` event which also emits before the attribute state of objects is expired. Change-Id: I9c572656ec5a9bfaeab817e9c95107c75aca1b51 Fixes: #3934
* Support python3.6Mike Bayer2017-01-131-5/+6
| | | | | | | | | | | Corrects some warnings and adds tox config. Adds DeprecationWarning to the error category. Large sweep for string literals w/ backslashes as this is common in docstrings Co-authored-by: Andrii Soldatenko Fixes: #3886 Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
* Merge "update for 2017 copyright"mike bayer2017-01-091-1/+1
|\
| * update for 2017 copyrightMike Bayer2017-01-041-1/+1
| | | | | | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* | Ensure session.no_autoflush uses finallyplumSemPy2017-01-041-2/+4
|/ | | | | | | | | | The :attr:`.Session.no_autoflush` context manager now ensures that the autoflush flag is reset within a "finally" block, so that if an exception is raised within the block, the state still resets appropriately. Pull request courtesy Emin Arakelian. Change-Id: Ib19ddf32074b1df82a6a1f1ae14e3a962cd31a5f Pull-request: https://github.com/zzzeek/sqlalchemy/pull/335
* Restore object to the identity_map upon delete() unconditionallyMike Bayer2016-10-271-3/+6
| | | | | | | | | | | | | | | | Fixed regression caused by :ticket:`2677` whereby calling :meth:`.Session.delete` on an object that was already flushed as deleted in that session would fail to set up the object in the identity map (or reject the object), causing flush errors as the object were in a state not accommodated by the unit of work. The pre-1.1 behavior in this case has been restored, which is that the object is put back into the identity map so that the DELETE statement will be attempted again, which emits a warning that the number of expected rows was not matched (unless the row were restored outside of the session). Change-Id: I9a8871f82cb1ebe67a7ad54d888d5ee835a9a40a Fixes: #3839
* Ensure strong ref to obj before calling persistent_to_deleted, othersMike Bayer2016-10-031-1/+11
| | | | | | | | | | | | Add checks in spots where state.obj() might be late-GC'ed before we get a chance to call the event. There may be more cases of these which we should address as they come up. The Session should always be maintaining strong refs to objects that have pending operations left on them, so for these cases we need to ensure that ref remains long enough for the event to be called. Change-Id: I1a7c7bc57130acc11f54ad55924af2e36ac75101 Fixes: #3808
* - improve documentation for SessionTransaction re: parentMike Bayer2016-09-241-8/+71
| | | | | | | | | | and nested attributes and what these mean - improve linking for after_transaction_create() / after_transaction_end() events - add public .parent attribute to detect top-level transaction within these events Change-Id: Ie7382bc8fe5de226160dcb6a5019e19fcc5af38e
* Fix ArgumentError access in Session._add_bindMike Bayer2016-09-191-6/+4
| | | | | | Fixes: #3798 Change-Id: Ib4e6344b599e871f9d46d36a5aeb7ba3104dc99b Pull-request: https://github.com/zzzeek/sqlalchemy/pull/293
* Add "render_nulls" flag to bulk_insert as optional performance optimizationtsauerwein2016-06-061-6/+33
| | | | | | | | | | | | | | Currently, ``Session.bulk_insert_mappings`` omits NULL values which causes it to break up batches of inserts based on which batches contain NULL and which do not. By adding this flag, the same columns are rendered in the INSERT for all rows allowing them to be batched. The downside is that server-side defaults are omitted. Doctext-author: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: Iec5969304d4bdbf57290b200331bde02254aa3a5 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/243
* - don't load deferred columns on unexpire for merge with load=False,Diana Clarke2016-04-061-0/+7
| | | | | | | fixes #3488 Change-Id: Ic9577b800e4a4e2465ec7f3a2e95bd231f5337ee Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
* - Further continuing on the common MySQL exception case ofMike Bayer2016-03-231-12/+31
| | | | | | | | | a savepoint being cancelled first covered in :ticket:`2696`, the failure mode in which the :class:`.Session` is placed when a SAVEPOINT vanishes before rollback has been improved to allow the :class:`.Session` to still function outside of that savepoint. It is assumed that the savepoint operation failed and was cancelled. fixes #3680
* - Fixed bug in :meth:`.Session.merge` where an object with a compositeMike Bayer2016-02-111-2/+3
| | | | | | | | primary key that has values for some but not all of the PK fields would emit a SELECT statement leaking the internal NEVER_SET symbol into the query, rather than detecting that this object does not have a searchable primary key and no SELECT should be emitted. fixes #3647
* - fully hyperlink the docstring for make_transientMike Bayer2016-02-081-11/+47
| | | | | | | | | - establish make_transient and make_transient_to_detached as special-use, advanced use only functions - list all conditions under make_transient() under which an attribute will not be loaded and establish that make_transient() does not attempt to load all attributes before detaching the object from its session, fixes #3640
* - happy new yearMike Bayer2016-01-291-1/+1
|
* - revert the change first made in a6fe4dc, as we are now generalizingMike Bayer2016-01-281-14/+2
| | | | | | | | | | | | | | | | | | | | | | | the warning here to all safe_reraise() cases in Python 2. - Revisiting :ticket:`2696`, first released in 1.0.10, which attempts to work around Python 2's lack of exception context reporting by emitting a warning for an exception that was interrupted by a second exception when attempting to roll back the already-failed transaction; this issue continues to occur for MySQL backends in conjunction with a savepoint that gets unexpectedly lost, which then causes a "no such savepoint" error when the rollback is attempted, obscuring what the original condition was. The approach has been generalized to the Core "safe reraise" function which takes place across the ORM and Core in any place that a transaction is being rolled back in response to an error which occurred trying to commit, including the context managers provided by :class:`.Session` and :class:`.Connection`, and taking place for operations such as a failure on "RELEASE SAVEPOINT". Previously, the fix was only in place for a specific path within the ORM flush/commit process; it now takes place for all transational context managers as well. fixes #2696
* fix some typospr/220Nils Philippsen2015-12-081-1/+1
|
* - The :meth:`.Session.merge` method now tracks pending objects byMike Bayer2015-12-041-3/+17
| | | | | | | | primary key before emitting an INSERT, and merges distinct objects with duplicate primary keys together as they are encountered, which is essentially semi-deterministic at best. This behavior matches what happens already with persistent objects. fixes #3601