On 09/23/2016 04:24 PM, HP3 wrote:


I just tried cleaning up at `after_transaction_end` but the whole
history stopped working.


 It seems like `after_transaction_create`/`after_transaction_end`
surrounds the loading of a one-to-many relationship.Thus, when
`after_commit` happened, the `history_objects` dict had being emptied
and no history was created.

keep in mind the Session uses a thing called a "subtransaction", which is a logical demarcation around a set of operations whereby begin()/commit() is called, and if there was no outermost begin() /commit(), that results in an actual COMMIT at the end of the block. Otherwise, it's a no-op, but still is a begin/end of a transaction. These will surround every flush() that actually has database work to do, and a flush() will be invoked within an attribute load as part of autoflush.

basically you need to test the SessionTransaction to ensure its the "outermost" transaction.

Docs are unfortunately not explicit here so you need to test for "transaction.parent is None"


http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.SessionTransaction
        




Should I not use `after_transaction_end` and go back to `after_commit`
and perhaps `after_rollback` (or maybe `after_soft_rollback`) ?


The thing is that I only need to add the history-objects to the session
at commit time.


BTW - This might be related to
https://groups.google.com/forum/#!topic/sqlalchemy/g8AA5ofChTY

... I see that position is being set during the nested-transaction


--
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 https://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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to