diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-02-08 09:16:39 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-02-08 17:40:39 -0500 |
commit | c3ec789ecdd4e33786b8ac0f1ccdf155c15eda9d (patch) | |
tree | c7f31c22bd0912e3cef9b7951ce48ebde3a61829 /lib/sqlalchemy/orm/attributes.py | |
parent | cf64e2574cfdd29aaf9b60bbd1b18e026e18049a (diff) | |
download | sqlalchemy-c3ec789ecdd4e33786b8ac0f1ccdf155c15eda9d.tar.gz |
Add initiator argument to set_attribute
Added new argument :paramref:`.attributes.set_attribute.inititator`
to the :func:`.attributes.set_attribute` function, allowing an
event token received from a listener function to be propagated
to subsequent set events.
Change-Id: I6ede21e42153026ab46a1d2ec33aa3f999db98e2
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index b175297ac..e9227362e 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1592,7 +1592,7 @@ def set_committed_value(instance, key, value): state.manager[key].impl.set_committed_value(state, dict_, value) -def set_attribute(instance, key, value): +def set_attribute(instance, key, value, initiator=None): """Set the value of an attribute, firing history events. This function may be used regardless of instrumentation @@ -1601,9 +1601,24 @@ def set_attribute(instance, key, value): of this method to establish attribute state as understood by SQLAlchemy. + :param instance: the object that will be modified + + :param key: string name of the attribute + + :param value: value to assign + + :param initiator: an instance of :class:`.Event` that would have + been propagated from a previous event listener. This argument + is used when the :func:`.set_attribute` function is being used within + an existing event listening function where an :class:`.Event` object + is being supplied; the object may be used to track the origin of the + chain of events. + + .. versionadded:: 1.2.3 + """ state, dict_ = instance_state(instance), instance_dict(instance) - state.manager[key].impl.set(state, dict_, value, None) + state.manager[key].impl.set(state, dict_, value, initiator) def get_attribute(instance, key): |