> > > It's possible that if you're using the session in "autocommit" mode and > just want to occasionally "broadcast" your object state to a quick > "flush everything", that in fact turning off the "accounting" feature > with this flag is appropriate. I'm looking at this code and it really > is all about the thing you don't want, that is, anytime the transaction > goes away, erasing all the object state because we no longer know the > state of the DB. >
Thanks Mike, having read the source some more myself I agree :) > Trying to recall why I have expire_on_commit=False but there's no > expire_on_rollback, it's because after a commit, the only thing that can > make the database state change vs. what your objects have are other > transactions outside of what you have in front of you. but with > rollback, there could have been any number of insert/update/delete > within the last transaction that are gone. The state of the objects is > going to be a combination of data that was loaded from the DB that might > have been rolled back, data that was the result of server-side defaults > and sequences from INSERT statements that might have been rolled back, > and then values that came from the application, but those values are > organized onto an object structure that itself might not exist anymore > because the transaction was rolled back. I think the idea is that to > really try flushing again, you have to start from zero when the > transaction first started and replay everything, otherwise things will > not be the same as they were before. > That make complete sense. I guess the only way to avoid it would be to somehow take a snapshot of the state of all of the mapped objects and their status in the session when a transaction begins, and restore that after the corresponding rollback. I bet that could actually be implemented with some event listeners, though I guess that is just a more convoluted way of achieving the same thing as _enable_transaction_accounting=False. Would it make sense, do you think, to allow disabling of transaction accounting on a per transaction basis, instead of for the entire session? e.g. if I could say session.flush(enable_transaction_accounting=False) to disable it for the transaction it creates to do the flushing? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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.