summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/state.py
Commit message (Collapse)AuthorAgeFilesLines
* Run search and replace of symbolic module namesMike Bayer2020-04-141-5/+7
| | | | | | | | Replaces a wide array of Sphinx-relative doc references with an abbreviated absolute form now supported by zzzeeksphinx. Change-Id: I94bffcc3f37885ffdde6238767224296339698a2
* Run autoflush for column attribute load operationsMike Bayer2020-04-031-2/+1
| | | | | | | | | | | | | | | | | The "autoflush" behavior of :class:`.Query` will now trigger for nearly all ORM level attribute load operations, including when a deferred column is loaded as well as when an expired column is loaded. Previously, autoflush on load of expired or unloaded attributes was limited to relationship-bound attributes only. However, this led to the issue where column-based attributes that also depended on other rows, or even other columns in the same row, in order to express the correct value, would show an effectively stale value when accessed as there could be pending changes in the session left to be flushed. Autoflush is now disabled only in some cases where attributes are being unexpired in the context of a history operation. Fixes: #5226 Change-Id: Ibd965b30918cd273ae020411a704bf2bb1891f59
* Simplified module pre-loading strategy and made it linter friendlyFederico Caselli2020-03-071-6/+6
| | | | | | | | | | | | | | | | | Introduced a modules registry to register modules that should be lazily loaded in the package init. This ensures that they are in the system module cache, avoiding potential thread safety issues as when importing them directly in the function that uses them. The module registry is used to obtain these modules directly, ensuring that the all the lazily loaded modules are resolved at the proper time This replaces dependency_for decorator and the dependencies decorator logic, removing the need to pass the resolved modules as arguments of the decodated functions and removes possible errors caused by linters. Fixes: #4689 Fixes: #4656 Change-Id: I2e291eba4297867fc0ddb5d875b9f7af34751d01
* Warn for runid changing in load events; add restore_load_context flagMike Bayer2020-01-311-12/+4
| | | | | | | | | | | | | | | | | | | | Added a new flag :paramref:`.InstanceEvents.restore_load_context` and :paramref:`.SessionEvents.restore_load_context` which apply to the :meth:`.InstanceEvents.load`, :meth:`.InstanceEvents.refresh`, and :meth:`.SessionEvents.loaded_as_persistent` events, which when set will restore the "load context" of the object after the event hook has been called. This ensures that the object remains within the "loader context" of the load operation that is already ongoing, rather than the object being transferred to a new load context due to refresh operations which may have occurred in the event. A warning is now emitted when this condition occurs, which recommends use of the flag to resolve this case. The flag is "opt-in" so that there is no risk introduced to existing applications. The change additionally adds support for the ``raw=True`` flag to session lifecycle events. Fixes: #5129 Change-Id: I2912f48ac8c5636297d63ed383454930e8e9a6a3
* InstanceState default path is RootRegistry, not tupleMike Bayer2020-01-221-1/+1
| | | | | | | | | | | | | | | | Fixed regression caused in 1.3.13 by :ticket:`5056` where a refactor of the ORM path registry system made it such that a path could no longer be compared to an empty tuple, which can occur in a particular kind of joined eager loading path. The "empty tuple" use case has been resolved so that the path registry is compared to a path registry in all cases; the :class:`.PathRegistry` object itself now implements ``__eq__()`` and ``__ne__()`` methods which will take place for all equality comparisons and continue to succeed in the not anticipated case that a non- :class:`.PathRegistry` object is compared, while emitting a warning that this object should not be the subject of the comparison. Fixes: #5110 Change-Id: I6cab6cd771c131d12b17939b369212f12c6bee16
* happy new yearMike Bayer2020-01-011-1/+1
| | | | Change-Id: I08440dc25e40ea1ccea1778f6ee9e28a00808235
* Implement raiseload for deferred columnsMike Bayer2019-10-161-11/+8
| | | | | | | | | | | | | | | | | | | | | Added "raiseload" feature for ORM mapped columns. As part of this change, the behavior of "deferred" is now more strict; an attribute that is set up as "deferred" at the mapper level no longer participates in an "unexpire" operation; that is, when an unexpire loads all the expired columns of an object which are not themselves in a deferred group, those which are mapper-level deferred will never be loaded. Deferral options set at query time should always be reset by an expiration operation. Renames deferred_scalar_loader to expired_attribute_loader Unfortunately we can't have raiseload() do this because it would break existing wildcard behavior. Fixes: #4826 Change-Id: I30d9a30236e0b69134e4094fb7c1ad2267f089d1
* Run eager loaders on unexpireMike Bayer2019-08-231-1/+12
| | | | | | | | | | | | Eager loaders, such as joined loading, SELECT IN loading, etc., when configured on a mapper or via query options will now be invoked during the refresh on an expired object; in the case of selectinload and subqueryload, since the additional load is for a single object only, the "immediateload" scheme is used in these cases which resembles the single-parent query emitted by lazy loading. Change-Id: I7ca2c77bff58dc21015d60093a88c387937376b2 Fixes: #1763
* Hold implicitly created collections in a pending areaMike Bayer2019-05-271-0/+4
| | | | | | | | | | | | | | | Accessing a collection-oriented attribute on a newly created object no longer mutates ``__dict__``, but still returns an empty collection as has always been the case. This allows collection-oriented attributes to work consistently in comparison to scalar attributes which return ``None``, but also don't mutate ``__dict__``. In order to accommodate for the collection being mutated, the same empty collection is returned each time once initially created, and when it is mutated (e.g. an item appended, added, etc.) it is then moved into ``__dict__``. This removes the last of mutating side-effects on read-only attribute access within the ORM. Fixes: #4519 Change-Id: I06a058d24e6eb24b5c6b6092d3f8b31cf9c244ae
* Note for history methods that history is reset per-flush.Mike Bayer2019-02-091-2/+19
| | | | Change-Id: I9bc4d0ddfa93f13e6717b89fa9934f1b8052147f
* Fix many spell glitchesLele Gaifax2019-01-251-1/+1
| | | | | | | | | | | | 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
* happy new yearMike Bayer2019-01-111-1/+1
| | | | Change-Id: I6a71f4924d046cf306961c58dffccf21e9c03911
* Post black reformattingMike Bayer2019-01-061-19/+20
| | | | | | | | | | | | | 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-104/+129
| | | | | | | | | | | | | | 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
* Modernize deferred callable for many-to-one comparisonMike Bayer2018-11-101-2/+28
| | | | | | | | | | | | | | | | | | | | | | 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
* Add .info to InstanceStateMike Bayer2018-10-011-2/+4
| | | | | | | | Added ``.info`` dictionary to the :class:`.InstanceState` class, the object that comes from calling :func:`.inspect` on a mapped object. Fixes: #4257 Change-Id: I32d043f369edb708a17eec2e0b8876db0c1891b4
* Look for dict builtin in InstanceState cleanupRomuald Brunet2018-09-181-0/+7
| | | | | | | | | | 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
* happy new yearMike Bayer2018-01-121-1/+1
| | | | Change-Id: I3ef36bfd0cb0ba62b3123c8cf92370a43156cf8f
* Add an identity_token to the identity keyMike Bayer2017-12-221-10/+24
| | | | | | | | | For the purposes of assisting with sharded setups, add a new member to the identity key that can be customized. this allows sharding across databases where the primary key space is shared. Change-Id: Iae3909f5d4c501b62c10d0371fbceb01abda51db Fixes: #4137
* Don't expire "deferred" attributes in make_transient_to_detachedMike Bayer2017-09-261-0/+13
| | | | | | | | | | 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
* Enable multi-level selectin polymorphic loadingMike Bayer2017-08-071-0/+1
| | | | | Change-Id: Icc742bbeecdb7448ce84caccd63e086af16e81c1 Fixes: #4026
* Raise on flag_modified() for non-present attributeMike Bayer2017-03-211-14/+19
| | | | | | | | | | | | 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
* update for 2017 copyrightMike Bayer2017-01-041-1/+1
| | | | Change-Id: I4e8c2aa8fe817bb2af8707410fa0201f938781de
* Ensure strong ref to obj before calling persistent_to_deleted, othersMike Bayer2016-10-031-4/+12
| | | | | | | | | | | | 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
* - don't load deferred columns on unexpire for merge with load=False,Diana Clarke2016-04-061-1/+11
| | | | | | | fixes #3488 Change-Id: Ic9577b800e4a4e2465ec7f3a2e95bd231f5337ee Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
* - fully hyperlink the docstring for make_transientMike Bayer2016-02-081-1/+1
| | | | | | | | | - 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
|
* - reduce some callcounts within the new eventsMike Bayer2015-09-031-1/+1
|
* - The :class:`.SessionEvents` suite now includes events to allowticket_2677Mike Bayer2015-09-021-7/+105
| | | | | | | | | | | | | | | | | | | | | unambiguous tracking of all object lifecycle state transitions in terms of the :class:`.Session` itself, e.g. pending, transient, persistent, detached. The state of the object within each event is also defined. fixes #2677 - Added a new session lifecycle state :term:`deleted`. This new state represents an object that has been deleted from the :term:`persistent` state and will move to the :term:`detached` state once the transaction is committed. This resolves the long-standing issue that objects which were deleted existed in a gray area between persistent and detached. The :attr:`.InstanceState.persistent` accessor will **no longer** report on a deleted object as persistent; the :attr:`.InstanceState.deleted` accessor will instead be True for these objects, until they become detached. - The :paramref:`.Session.weak_identity_map` parameter is deprecated. See the new recipe at :ref:`session_referencing_behavior` for an event-based approach to maintaining strong identity map behavior. references #3517
* - repair the inspection hook in sqltypes to not be fooledMike Bayer2015-08-221-0/+2
| | | | by mock and other __getattr__ impostors
* - add tests for InstanceEvents.init, InstanceEvents.init_failureMike Bayer2015-08-141-1/+1
| | | | | | | - ensure that kwargs can be modified in-place within InstanceEvents.init and that these take effect for the __init__ method. - improve documentation for these and related events, including that kwargs can be modified in-place.
* - Fixed 1.0 regression where the "noload" loader strategy would failMike Bayer2015-08-111-6/+0
| | | | | | | | | to function for a many-to-one relationship. The loader used an API to place "None" into the dictionary which no longer actually writes a value; this is a side effect of :ticket:`3061`. - remove InstanceState._initialize() totally, it's used nowhere else and no longer does what it says it does - fill in fowards-port version ids throughout the changes for 1.0.9
* - copyright 2015Mike Bayer2015-03-101-1/+1
|
* - Mapped state internals have been reworked to allow for a 50% reductionMike Bayer2015-02-181-47/+102
| | | | | | | | in callcounts specific to the "expiration" of objects, as in the "auto expire" feature of :meth:`.Session.commit` and for :meth:`.Session.expire_all`, as well as in the "cleanup" step which occurs when object states are garbage collected. fixes #3307
* - Fixed bug where :meth:`.Session.expunge` would not fully detachMike Bayer2014-10-191-1/+10
| | | | | | | the given object if the object had been subject to a delete operation that was flushed, but not committed. This would also affect related operations like :func:`.make_transient`. fixes #3139
* improve exception vs. exit handlingndparker2014-09-231-2/+2
|
* - defaultdict benchmarks faster than a namedtuple; OKMike Bayer2014-08-291-14/+0
| | | | - inline the column-based expiration operations as well
* - use a faster discard when loadingMike Bayer2014-08-291-2/+1
| | | | - don't do a bool on identity map since it calls __len__
* - rename _InspectionAttr to InspectionAttrMike Bayer2014-08-131-1/+1
|
* - apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,Brian Jarrett2014-07-201-25/+27
| | | | sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing
* - break up the <authors> copyright comment as part of a passMike Bayer2014-07-091-1/+2
| | | | to get all flake8 passing
* - revert the memoized committed_state / callables changes as they appear to ↵Mike Bayer2014-05-241-19/+8
| | | | | | add to lazy loading. not really clear which approach is better in the long run.
* inliningMike Bayer2014-05-191-10/+21
|
* - some inlining, speed up identity mapMike Bayer2014-05-191-4/+8
|
* - add some docs for the instancestate linkage to the inspection systemMike Bayer2014-04-041-5/+67
|
* - Fixed bug in mutable extension as well asMike Bayer2014-03-191-2/+2
| | | | | | :func:`.attributes.flag_modified` where the change event would not be propagated if the attribute had been reassigned to itself. fixes #2997
* - happy new yearMike Bayer2014-01-051-1/+1
|
* - The ``viewonly`` flag on :func:`.relationship` will now preventMike Bayer2013-11-191-0/+2
| | | | | | | | | | attribute history from being written on behalf of the target attribute. This has the effect of the object not being written to the Session.dirty list if it is mutated. Previously, the object would be present in Session.dirty, but no change would take place on behalf of the modified attribute during flush. The attribute still emits events such as backref events and user-defined events and will still receive mutations from backrefs. [ticket:2833]
* - :func:`.attributes.get_history()` when used with a scalar column-mappedMike Bayer2013-10-251-1/+31
| | | | | | | | | attribute will now honor the "passive" flag passed to it; as this defaults to ``PASSIVE_OFF``, the function will by default query the database if the value is not present. This is a behavioral change vs. 0.8. [ticket:2787] - Added new method :meth:`.AttributeState.load_history`, works like :attr:`.AttributeState.history` but also fires loader callables.
* use accepts scalar loader here so we deal with _ProxyImpl correctlyMike Bayer2013-10-111-6/+4
|