On May 28, 2010, at 1:24 PM, Kent wrote:

> 
> 
> On May 27, 6:39 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> 
>> commit() releases the savepoint, if thats whats going on contextually.   It 
>> doesnt actually commit the outer transaction if you've last called 
>> begin_nested().
>> 
> 
> 
> In a SessionExtension, 'before_commit' is called for nested
> transactions, which do not actually perform a database commit, as well
> as the RootTransaction, which does issue a COMMIT.
> 
> I believe the zope guys overlooked this when they wrote their 'def
> before_commit()' method of their SessionExtension, and I am going to
> attempt to fix this.
> 
>    def before_commit(self, session):
>        assert zope_transaction.get().status == 'Committing',
> "Transaction must be committed using the transaction manager"
> 
> So my question is, first, do you call before_commit() on
> SessionExtensions intentionally *even for nested transactions* which
> are not performing a database commit?  I assume the answer is "yes,
> that is by design".

it is by design, yes.     you ultimately need to look at the transaction itself 
if you want to determine if its the "real" commit.  the entire session 
conversation could be nested inside of a larger begin/commit external to the 
session, for example (I just illustrated a unit test recipe that uses this 
technique if you search around yesterday's messages).

> 
> Which leads to this question: Inside a SessionExtension's
> before_commit() method, how can I work out whether this is a nested
> transaction vs. the root transaction?

you'd look at session.transaction for details.  to get the engine.Transaction 
object you'd need to dig into its _connections dictionary, but for most 
purposes you can probably just look at transaction.nested.


> 
> Thanks,
> Kent
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to