On Dec 17, 2011, at 9:04 AM, Andronikos Nedos wrote:

> Hi all,
> 
> We make heavy use of SqlAchemy in our app and use a custom 2-phase commit 
> protocol over HTTP to communicate
> with mobile devices. 
> 
> While all read,write,deletes happen in a first HTTP request, a subsequent 
> HTTP request needs to find the transaction and either commit or abort. i.e.,
> 
> request 1, start tx
> read,write,deletes
> 
> request 2, find tx
> commit or abort tx
> 
> There's no requirement per se for sesion objects to be migrated from one 
> thread to another one, but is it safe to save/pickle the SessionTransaction
> object, until another request in another thread decides that all work done 
> should be committed or aborted ?

Yikes, not at all- SessionTransaction holds onto DBAPI connections and they 
don't move.   Not like this wouldn't be an interesting feature,  it would 
involve custom __getstate__()/__setstate__(), and then a lot of tests.     But 
while I've been aware of this pattern in theory, in 16 years of web programming 
I've never heard of anyone actually doing it.  

But we do support two phase transactions and XID so the mechanics are there to 
achieve this effect more manually.

If you are using 2-phase to resurrect transactions into a new process, you need 
to use Connection directly along with begin_twophase:

http://www.sqlalchemy.org/docs/core/connections.html#sqlalchemy.engine.base.Connection.begin_twophase

where you'll note you can pass the xid.  The xid is the thing you actually need 
to be carrying along between requests.

Then you bind your Session to that connection using the techniques at 
http://www.sqlalchemy.org/docs/orm/session.html#joining-a-session-into-an-external-transaction.



> If the SessionTransaction is unsuitable, is there
> another way to refer to an existing live transaction from a subsequent 
> request ?
> 
> We use the zodb transaction, zope.sqlalchemy, tm2 machinery at the moment, so 
> it's possibly to write our own TransactionManager, but the question is really 
> on how do we find and resurrect an existing SA transaction.
> 
> Thanks for all your help,
> Andronikos
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/zerH87cr-OIJ.
> To post to this group, send email to sqlalchemy@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 sqlalchemy@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