On 7/24/15 10:13 AM, Richard Gerd Kuesters wrote:
hi!

first, /yes/, set and after_flush are quite different events :) but here's what i'm trying to accomplish:

one object have an attribute, like 'state', and i would like to monitor and trigger some other methods if (given scenarios):

1. the program sets a new value to a state that is equal to it's actual state (and/or value), i can use 'set' but, does it reflect only the value set or when it gets commited?
you set the value to the attribute, the "set" event receives it, if the attribute already *had* that value loaded then the history is a no-net change, no UPDATE is emitted. If the attribute did not already have a value loaded, and the attribute does not specify "active_history", then we don't know the "old" value and the history will show that the attribute has changed, from a previous value of NO_VALUE.

I don't know what "does it reflect only the value set or when it gets committed" means, hopefully the above answers your question.

1.1. and, if set to the same value, returning the old value (set with retval=True) will make this object dirty (supposed to be the only value modified) ?
the object goes into session.dirty as soon as any attributes are set. however, in the flush, we go through the effort to look for actual net changes. If there's no net change on the attribute, no UPDATE will be emitted in the flush, the object moves back to clean at that point.

2. after_flush, if one of these entity get's modified, can i track down what was modified, including my "state" column if possible?
yes you can look in session.dirty to find all the objects that are dirty, then looking in "committed_state" will illustrate those attribute that had something happen to them; though the latter part here is not a "public" system - it will work for now but I can't guarantee that in a future major version bump that system wouldn't change. We can add public API to return ".modified", e.g. a list of keys that received a modified event.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to