SamDonaldson wrote:
>[...]
> I have defined a transaction decorator:
> def transaction(func):
>     def do(*args, **kw):
>         connection = engine.connect()
>         transaction = connection.begin()
>         try:
>           # create some context here for the connection and pass it
> through to later execute
>           ret = func(ctx, *args, **kw)
>           transaction.commit()
>           connection.close()
>           return ret
>         except:
>           # rollback for now
>           transaction.rollback()
>           connection.close()
>     return do
> 
 > [...]
> The problem occurs when I nest these like this:
> 
> @transaction
> def blah(...)
>     Do a vanilla INSERT into mysql
> 
> @transaction
> def blah2(...)
>    Do some work here and then call blah like this:
>    <work>
>    id = blah(...)  <--- hang happens here
> 
> My assumption was that sqlalchemy would handle this as nested
> transactions based on incrementing.  How does this affect the
> connection pool etc..?  Any help in understanding this behavior would
> be appreciated.

With engine.connect() you are pulling a new and unrelated db connection 
in each invocation of your transaction decorator.  If you want each 
invocation to 'nest' in the same transaction context, you'd need to 
either explicitly pass along the connection or use a threadlocal engine.

http://www.sqlalchemy.org/docs/dbengine.html#dbengine_transactions


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to