From b9a2b58dd74757184ef94206f09e9db1f536e4cb Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 19 Mar 2014 11:09:38 -0400 Subject: - Fixed bug in mutable extension as well as :func:`.attributes.flag_modified` where the change event would not be propagated if the attribute had been reassigned to itself. fixes #2997 --- lib/sqlalchemy/ext/mutable.py | 3 +++ lib/sqlalchemy/orm/attributes.py | 2 +- lib/sqlalchemy/orm/state.py | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py index 4e574935d..7869e888c 100644 --- a/lib/sqlalchemy/ext/mutable.py +++ b/lib/sqlalchemy/ext/mutable.py @@ -437,6 +437,9 @@ class MutableBase(object): outgoing. """ + if value is oldvalue: + return value + if not isinstance(value, cls): value = cls.coerce(key, value) if value is not None: diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 7647bf9d0..3a786c73d 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1538,4 +1538,4 @@ def flag_modified(instance, key): """ state, dict_ = instance_state(instance), instance_dict(instance) impl = state.manager[key].impl - state._modified_event(dict_, impl, NO_VALUE) + state._modified_event(dict_, impl, NO_VALUE, force=True) diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py index 9712dd055..fb5db1fc9 100644 --- a/lib/sqlalchemy/orm/state.py +++ b/lib/sqlalchemy/orm/state.py @@ -414,10 +414,10 @@ class InstanceState(interfaces._InspectionAttr): def _instance_dict(self): return None - def _modified_event(self, dict_, attr, previous, collection=False): + def _modified_event(self, dict_, attr, previous, collection=False, force=False): if not attr.send_modified_events: return - if attr.key not in self.committed_state: + if attr.key not in self.committed_state or force: if collection: if previous is NEVER_SET: if attr.key in dict_: -- cgit v1.2.1