On 12/08/2015 07:41 AM, Юрий Пайков wrote: > I run a program which creates, fills and merges to DB a list of mapped > objects. I need to know if a merge created a new instance in a database > or if it updated previously existing one or if it did noop. When I know > the instance is persistent, my goal is to figure out if it's going to be > updated after COMMIT. > I use > | > session.is_modified(object) > | > for that. > If the first object in the list is truly not modified, this function > correctly reports False. But for the next objects it returns True and > blames one of the relationship attributes. > As it turns out, for the first object state.committed_state includes the > actual value of the relationship attribute - related object, while for > the others it is > | > symbol(PASSIVE_NO_DELETE) > | > and so the current value of the relationship is wrongly considered "added".
We have a lot of "PASSIVE_*" symbols, but I can't find one, even looking way back, that is called "PASSIVE_NO_DELETE". Also these particular symbols don't get populated into objects, they are arguments we send to various attribute fetch/history methods. If I had to guess, you *might* be seeing PASSIVE_NO_RESULT, but that wouldn't be present in committed_state. Overall this description of behavior is not clear. If you could reproduce your exact results in a console session or script and please report on those exactly, that would help understand your case. Following the guidelines at http://stackoverflow.com/help/mcve would be most helpful. The is_modified() method up until 0.8 included a default setting for its own "passive" flag that would cause it to fetch relationships as a side effect. This was fixed in 0.8. Also it does not include collection-bound relationships as part of its answer unless the include_collections flag is set to True. > > Does anyone know why it happens like this? How can I correctly check if > the object's going to be updated on commit? > > -- > 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] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
