On Dec 17, 2011, at 2:24 PM, Andronikos Nedos wrote:

> 
> So, if I understand correctly, I need to maintain the Connection object 
> between requests and on the 2nd request bind a session to the existing 
> Connection object and then 
> session.commit() or session.abort() ? The question now is how can I persist 
> the connection object between requests, is in-memory the only option here ?

One or both of us might be misunderstanding parts of the background here, but 
my current take on it is that you want one request to end completely, but for 
the database to maintain the transaction.  Then you'd like to resume the 
transaction in a subsequent request.   This approach uses a transaction that 
was created using PREPARE TRANSACTION along with an XID.    When that technique 
is used, the database, let's say its Postgresql, will persistently hold onto 
the transaction noted by an XID after the connection which created it is gone.  
 An entirely new database connection can resume this transaction by again 
calling BEGIN PREPARED with the same XID.

So what I'm suggesting is that the string "XID" symbol is the only thing you 
need to carry across to the second request, in order to pick up again on that 
same transaction.   You'd never want to hold DBAPI connections or any other 
kind of resource like that between requests.    The XID approach is already 
quite dangerous, as if your second HTTP request never comes in, you have a 
dangling transaction in your database, locks and all.   The only way to zap 
these is to query through pg_stat_activity, get their ids and cancel them with 
"ROLLBACK PREPARED <xid>".

> 
> Thanks for 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/-/Qm_KtbuE2GsJ.
> 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.

-- 
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.

Reply via email to