diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-02 20:45:44 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-03 13:47:57 -0400 |
| commit | c7d3ca0da477451885158a923aa9ee7e49794541 (patch) | |
| tree | 9f5255bbec244ef8abce42bd8694aae9631e70a7 /lib/sqlalchemy/orm/session.py | |
| parent | 49b6c50016c8a038a6df7104560bb3945debe064 (diff) | |
| download | sqlalchemy-c7d3ca0da477451885158a923aa9ee7e49794541.tar.gz | |
Run autoflush for column attribute load operations
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
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index c773aeb08..aa55fab58 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1663,9 +1663,7 @@ class Session(_SessionClassMethods): ) util.raise_(e, with_traceback=sys.exc_info()[2]) - def refresh( - self, instance, attribute_names=None, with_for_update=None, - ): + def refresh(self, instance, attribute_names=None, with_for_update=None): """Expire and refresh the attributes on the given instance. A query will be issued to the database and all attributes will be @@ -1834,7 +1832,7 @@ class Session(_SessionClassMethods): for o, m, st_, dct_ in cascaded: self._conditional_expire(st_) - def _conditional_expire(self, state): + def _conditional_expire(self, state, autoflush=None): """Expire a state if persistent, else expunge if pending""" if state.key: |
