On Aug 4, 2006, at 8:29 PM, Tzahi Fadida wrote:

> I am not saying there has to be close/rollback/commit,
> however, i am convinced that when a transaction/sessionTransaction
> object is non existant anymore, then at least the connection must  
> be freed.
> i.e. it just occupies memory and a slot in the pool.
> It is just like a memory leak and a resource leak.
>
> What i suggest is that the __del__ or whatever will check if the
> transaction was unresolved and just free the connection. The  
> database will
> decide what to do next, SQLAlchemy is supposed to be an API/link to  
> the
> database. I.e., this has nothing to do with transactions and more  
> about
> freeing defunct resources you can no longer access.

actually, all connections that are freed by the pool have a rollback 
() called on them automatically.

also, connections are returned to the pool when the proxying object  
of the connection has its __del__ method called, so the behavior you  
want is already there.  if you lose all references to a  
SessionTransaction as well as the Session its associated with, when  
they get garbage collected, so will all connections theyre holding  
onto, and the connection will be returned to the pool (and the  
rollback() will be performed).  assuming your engine is not using the  
"threadlocal" strategy.

if you are using the "threadlocal" strategy, not as simple; the  
engine is holding on to the current transaction associated with the  
current thread;  its by design that you dont have to hold on to any  
transactional object, and the transaction remains open, until  
explicitly committed or rolled back (which can be performed directly  
off the engine in the case of 'threadlocal').

if you want very explicit management of resources, not using  
"threadlocal" for your create_engine() strategy, using "default"  
instead, is the first step.

also, even though the functionality you want is present, it strikes  
me as a poor practice to use a SessionTransaction without a try:/ 
finally: block that explicitly calls rollback() or commit() on it.    
I cant think of a reason youd want to begin a transaction and then  
just let it fall away without managing its closure; it seems to  
defeat the purpose of a transaction, which is, demarcation of a set  
of operations.



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to