summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/properties.py3
-rw-r--r--lib/sqlalchemy/orm/session.py7
-rw-r--r--lib/sqlalchemy/orm/state.py12
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index 8197e041f..f3dce7541 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -218,7 +218,8 @@ class ColumnProperty(StrategizedProperty):
impl = dest_state.get_impl(self.key)
impl.set(dest_state, dest_dict, value, None)
elif dest_state.has_identity and self.key not in dest_dict:
- dest_state._expire_attributes(dest_dict, [self.key])
+ dest_state._expire_attributes(
+ dest_dict, [self.key], no_loader=True)
class Comparator(util.MemoizedSlots, PropComparator):
"""Produce boolean, comparison, and other operators for
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index dc5de7ac6..1cf1bdb24 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1842,6 +1842,13 @@ class Session(_SessionClassMethods):
merged_state.load_path = state.load_path
merged_state.load_options = state.load_options
+ # since we are copying load_options, we need to copy
+ # the callables_ that would have been generated by those
+ # load_options.
+ # assumes that the callables we put in state.callables_
+ # are not instance-specific (which they should not be)
+ merged_state._copy_callables(state)
+
for prop in mapper.iterate_properties:
prop.merge(self, state, state_dict,
merged_state, merged_dict,
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 1ad09ee83..2704367f9 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -485,6 +485,10 @@ class InstanceState(interfaces.InspectionAttr):
if self.callables:
self.callables.pop(key, None)
+ def _copy_callables(self, from_):
+ if 'callables' in from_.__dict__:
+ self.callables = dict(from_.callables)
+
@classmethod
def _instance_level_callable_processor(cls, manager, fn, key):
impl = manager[key].impl
@@ -537,7 +541,7 @@ class InstanceState(interfaces.InspectionAttr):
self.manager.dispatch.expire(self, None)
- def _expire_attributes(self, dict_, attribute_names):
+ def _expire_attributes(self, dict_, attribute_names, no_loader=False):
pending = self.__dict__.get('_pending_mutations', None)
callables = self.callables
@@ -545,6 +549,12 @@ class InstanceState(interfaces.InspectionAttr):
for key in attribute_names:
impl = self.manager[key].impl
if impl.accepts_scalar_loader:
+ if no_loader and (
+ impl.callable_ or
+ key in callables
+ ):
+ continue
+
self.expired_attributes.add(key)
if callables and key in callables:
del callables[key]