diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-05-22 15:42:59 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-05-23 15:14:04 -0400 |
commit | f46551de450a76de4105bda3be8d0d5c5fc0d52c (patch) | |
tree | 2bf640007f988f6851c359eee7e38886b81239d9 /lib/sqlalchemy/orm/attributes.py | |
parent | a987942761542666be89f40a9ac4a35e001b8265 (diff) | |
download | sqlalchemy-f46551de450a76de4105bda3be8d0d5c5fc0d52c.tar.gz |
Add AttributeEvents.modified
Added new event handler :meth:`.AttributeEvents.modified` which is
triggered when the func:`.attributes.flag_modified` function is
invoked, which is common when using the :mod:`sqlalchemy.ext.mutable`
extension module.
Change-Id: Ic152f1d5c53087d780b24ed7f1f1571527b9e8fc
Fixes: #3303
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 23a9f1a8c..f3a5c4735 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -330,6 +330,7 @@ OP_REMOVE = util.symbol("REMOVE") OP_APPEND = util.symbol("APPEND") OP_REPLACE = util.symbol("REPLACE") OP_BULK_REPLACE = util.symbol("BULK_REPLACE") +OP_MODIFIED = util.symbol("MODIFIED") class Event(object): @@ -341,9 +342,9 @@ class Event(object): operations. The :class:`.Event` object is sent as the ``initiator`` argument - when dealing with the :meth:`.AttributeEvents.append`, + when dealing with events such as :meth:`.AttributeEvents.append`, :meth:`.AttributeEvents.set`, - and :meth:`.AttributeEvents.remove` events. + and :meth:`.AttributeEvents.remove`. The :class:`.Event` object is currently interpreted by the backref event handlers, and is used to control the propagation of operations @@ -459,12 +460,18 @@ class AttributeImpl(object): self.dispatch._active_history = True self.expire_missing = expire_missing + self._modified_token = None __slots__ = ( 'class_', 'key', 'callable_', 'dispatch', 'trackparent', - 'parent_token', 'send_modified_events', 'is_equal', 'expire_missing' + 'parent_token', 'send_modified_events', 'is_equal', 'expire_missing', + '_modified_token' ) + def _init_modified_token(self): + self._modified_token = Event(self, OP_MODIFIED) + return self._modified_token + def __str__(self): return "%s.%s" % (self.class_.__name__, self.key) @@ -1636,6 +1643,8 @@ def flag_modified(instance, key): """ state, dict_ = instance_state(instance), instance_dict(instance) impl = state.manager[key].impl + impl.dispatch.modified( + state, impl._modified_token or impl._init_modified_token()) state._modified_event(dict_, impl, NO_VALUE, is_userland=True) |