On Mar 26, 2013, at 4:24 PM, Evan Hammer <[email protected]> wrote:
> I'd like to get notified (either by checking the session or through an event > handler) when an attribute changes value. None of the options I've figured > out so far work for this. Thanks for the help! > > Event Handler > event.listen(Object.attribute, 'set', event_handler) > this method fires before the Object gets all the attributes from the database > so the Object isn't really usable. well its a "set" event, it doesn't inherently correspond to any kind of "get", you can certainly fetch data within a set event handler if that helps... > > > Session.Dirty > session.dirty: I can check the updated object before I commit it but I can't > figure out a way to get the oldvalue here. history doesn't seem to provide an > access point. > for o in session.dirty: > if o.is_modified(): > inspect(o).attrs.attribute.history history will give you the old and new value. If you aren't seeing the old value, that's because SQLAlchemy doesn't usually load the "old" value if it isn't already present, unless it needs it for the eventual flush. you can force this value to be present using active_history=True via column_property() or relationship(). an example with column_property(): http://docs.sqlalchemy.org/en/rel_0_8/orm/mapper_config.html?highlight=active_history#using-column-property-for-column-level-options -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
