Re: [sqlalchemy] set vs after_flush events
will this answer my second question? obj._sa_instance_state.committed_state {'batch_status': STARTED(db=1), 'updated_by': 24769797950537744L, 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]} cheers, richard. On 07/24/2015 11: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? 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) ? 2. after_flush, if one of these entity get's modified, can i track down what was modified, including my state column if possible? cheers, richard. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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. attachment: richard.vcf
Re: [sqlalchemy] set vs after_flush events
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.
Re: [sqlalchemy] set vs after_flush events
On 07/24/2015 12:59 PM, Mike Bayer wrote: 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. yup, it does answer it! i'm aware of the active_history, I was just wondering when an updated is stated, but it seems that you already took care of this job :) 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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. attachment: richard.vcf
Re: [sqlalchemy] set vs after_flush events
obj._sa_instance_state.committed_state.get('key') == obj._sa_instance_state.dict.get('key') False is this all that's necessary to track down what's modified and the past state (i believe to be sa_instance_state.dict) ? cheers, richard. On 07/24/2015 11:34 AM, Richard Gerd Kuesters wrote: will this answer my second question? obj._sa_instance_state.committed_state {'batch_status': STARTED(db=1), 'updated_by': 24769797950537744L, 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]} cheers, richard. On 07/24/2015 11: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? 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) ? 2. after_flush, if one of these entity get's modified, can i track down what was modified, including my state column if possible? cheers, richard. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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. attachment: richard.vcf
Re: [sqlalchemy] set vs after_flush events
On 7/24/15 10:45 AM, Richard Gerd Kuesters wrote: obj._sa_instance_state.committed_state.get('key') == obj._sa_instance_state.dict.get('key') False is this all that's necessary to track down what's modified and the past state (i believe to be sa_instance_state.dict) ? I'd prefer you use the public APIs but sure, those are the mechanics of it right now. cheers, richard. On 07/24/2015 11:34 AM, Richard Gerd Kuesters wrote: will this answer my second question? obj._sa_instance_state.committed_state {'batch_status': STARTED(db=1), 'updated_by': 24769797950537744L, 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]} cheers, richard. On 07/24/2015 11: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? 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) ? 2. after_flush, if one of these entity get's modified, can i track down what was modified, including my state column if possible? cheers, richard. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: [sqlalchemy] set vs after_flush events
yes, a public api would be awesome, perhaps for a future version? :) for now, i'll stick to that -- since it works, heh. cheers, richard. On 07/24/2015 12:59 PM, Mike Bayer wrote: On 7/24/15 10:45 AM, Richard Gerd Kuesters wrote: obj._sa_instance_state.committed_state.get('key') == obj._sa_instance_state.dict.get('key') False is this all that's necessary to track down what's modified and the past state (i believe to be sa_instance_state.dict) ? I'd prefer you use the public APIs but sure, those are the mechanics of it right now. cheers, richard. On 07/24/2015 11:34 AM, Richard Gerd Kuesters wrote: will this answer my second question? obj._sa_instance_state.committed_state {'batch_status': STARTED(db=1), 'updated_by': 24769797950537744L, 'updated_on': Arrow [2015-07-24T14:02:03.360479-03:00]} cheers, richard. On 07/24/2015 11: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? 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) ? 2. after_flush, if one of these entity get's modified, can i track down what was modified, including my state column if possible? cheers, richard. -- 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 mailto: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. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 mailto:sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com mailto:sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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. attachment: richard.vcf
[sqlalchemy] set vs after_flush events
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? 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) ? 2. after_flush, if one of these entity get's modified, can i track down what was modified, including my state column if possible? cheers, richard. -- 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. attachment: richard.vcf