On May 12, 2011, at 7:25 AM, Luper Rouch wrote: >> I still have the exact same issue when using SessionExtension's >> before_flush() and after_flush_postexec() methods, demonstrated here >> :http://paste.pocoo.org/show/387444/ >> >> Line 87 raises the same "InvalidRequestError: The transaction is >> inactive due to a rollback in a subtransaction. Issue rollback() to >> cancel the transaction." error. > > Someone on IRC suggested to do the rollback twice in > handle_exceptions(). This seems to work and solve the issue.
right, you're using begin(subtransactions=True). That will allow you to have an "inner" "transaction" block, but won't save you from the fundamental nature of the Session, in that it expects a rollback/commit for every transaction block (or a close() cancels everything). The reason "subtransactions=True" is required, is literally just a, "by setting this flag you agree that you really want to be doing this". Its a flag that is really not needed for the vast majority of use cases. In your test, the rationale for the @handle_exceptions decorator is not really clear. The Session's maintream mode of usage is, just use it, then call rollback() or commit() at the end - the "nesting" capability is to allow code that runs unconditionally in a transaction, regardless of whether or not the Session is in "autocommit" mode. If you don't plan on ever dealing with a Session in "autocommit" mode, the nesting of the transaction block doesn't really have much use. after_flush_postexec() in particular is already within the flush() processes' internal transaction block. Feel free to come up with a brief description of what you're really trying to do from a usage standpoint - i.e. not what part of Session you want to jiggle with but how the program would actually make use of what's going on. Throughout these messages, that remains unclear, and more detail would make the rationale/use case you're proposing apparent. -- 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.
