summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/loading.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-20 11:33:02 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-20 11:33:48 -0400
commit033e673f8771dfb20dd7b67a780c6ef3d3210e37 (patch)
tree988c3f65aa249a0ae9d541e5a44d84444ba88e6c /lib/sqlalchemy/orm/loading.py
parenta58c99977eafc5f69a3e37f9ddcc328698e7fe1e (diff)
downloadsqlalchemy-033e673f8771dfb20dd7b67a780c6ef3d3210e37.tar.gz
Narrow refresh populate_existing to just refresh_state
Fixed additional regression caused by the "eagerloaders on refresh" feature added in :ticket:`1763` where the refresh operation historically would set ``populate_existing``, which given the new feature now overwrites pending changes on eagerly loaded objects when autoflush is false. The populate_existing flag has been turned off for this case and a more specific method used to ensure the correct attributes refreshed. Fixes: #6326 Change-Id: I40315e4164eae28972c5839c04580d292bc6cb24
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r--lib/sqlalchemy/orm/loading.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index 12acfc5b7..ea6d0f1fe 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -481,7 +481,6 @@ def load_on_pk_identity(
_, load_options = _set_get_options(
compile_options,
load_options,
- populate_existing=bool(refresh_state),
version_check=version_check,
only_load_props=only_load_props,
refresh_state=refresh_state,
@@ -513,7 +512,6 @@ def load_on_pk_identity(
q._compile_options, load_options = _set_get_options(
compile_options,
load_options,
- populate_existing=bool(refresh_state),
version_check=version_check,
only_load_props=only_load_props,
refresh_state=refresh_state,
@@ -916,17 +914,23 @@ def _instance_processor(
state.session_id = session_id
session_identity_map._add_unpresent(state, identitykey)
+ effective_populate_existing = populate_existing
+ if refresh_state is state:
+ effective_populate_existing = True
+
# populate. this looks at whether this state is new
# for this load or was existing, and whether or not this
# row is the first row with this identity.
- if currentload or populate_existing:
+ if currentload or effective_populate_existing:
# full population routines. Objects here are either
# just created, or we are doing a populate_existing
# be conservative about setting load_path when populate_existing
# is in effect; want to maintain options from the original
# load. see test_expire->test_refresh_maintains_deferred_options
- if isnew and (propagated_loader_options or not populate_existing):
+ if isnew and (
+ propagated_loader_options or not effective_populate_existing
+ ):
state.load_options = propagated_loader_options
state.load_path = load_path
@@ -938,7 +942,7 @@ def _instance_processor(
isnew,
load_path,
loaded_instance,
- populate_existing,
+ effective_populate_existing,
populators,
)
@@ -966,7 +970,7 @@ def _instance_processor(
if state.runid != runid:
_warn_for_runid_changed(state)
- if populate_existing or state.modified:
+ if effective_populate_existing or state.modified:
if refresh_state and only_load_props:
state._commit(dict_, only_load_props)
else: