if you just set it to itself, that emits a change event. You could also set it to something like the current timestamp, and have your before_update() extension expire the changes on it after detection.
On Oct 27, 2010, at 1:48 PM, Nikolaj wrote: > Can you give an example of a forwards-compatible way to modify an > attribute to mark the instance dirty without creating actual net > changes? SA seems quite good at detecting my tricks. > > On Oct 27, 6:41 pm, Michael Bayer <[email protected]> wrote: >> On Oct 27, 2010, at 11:43 AM, Nikolaj wrote: >> >>> I have a mapped class called Widget, with an uninstrumented attribute >>> called 'owner' (i.e. it does not have a column representation). Widget >>> has a MapperExtension with a before_update() method that runs a couple >>> of queries using connection.execute() and sets some attributes on the >>> instance. >> >>> I would like Widget.owner to behave like an instrumented attribute in >>> the sense that modifying it forces a MapperExtension.before_update() >>> run at flush-time. Is that possible? >> >>> Alternatively, is there a way to force a before_update() run by >>> marking an instance as dirty (possibly by modifying attributes without >>> actual net changes)? In that case I could make Widget.owner into a >>> property and mark the instance dirty in the setter. >> >> that last idea would work and would be forwards-compatible. Otherwise >> you'd need to emit a modified event to instance_state(myobject) which isn't >> public API. >> >> >> >>> Thanks, >> >>> N >> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "sqlalchemy" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group >>> athttp://groups.google.com/group/sqlalchemy?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
