On Mon, May 17, 2021, at 4:21 PM, Anupama Goparaju wrote:
> Hi,
> 
> I see in the documentation 
> <https://docs.sqlalchemy.org/en/13/orm/session_basics.html> that we can bind 
> a connection to a SQLAlchemy session object:
> 
> *# at the module level, the global sessionmaker,* *# bound to a specific 
> Engine* 
> Session = sessionmaker(bind=engine) 
>  
> *#** later, some unit of code wants to create a* *# Session that is bound to 
> a specific Connection* conn = engine.connect() 
> session = Session(bind=conn)
> 
> How do we release the connection to an external connection pool safely? For 
> instance, if we are using a cx_Oracle SessionPool 
> <https://cx-oracle.readthedocs.io/en/latest/api_manual/session_pool.html> to 
> acquire and release connections? 
> session.close() is not doing that seamlessly in this case.
> 
> if we do, session = Session(bind=engine) - it usually releases connection to 
> the pool seamlessly on session.close().

if you acquire a connection using engine.connect(), you must release it to the 
connection pool using connection.close().  this is independent of the Session 
being bound to this Connection while it is acquired from the pool.   
Session.close() will not achieve this when you are using 
Session(bind=connection) as the Session understands the scope of this 
Connection is external to that Session.

This is then a separate issue from the use of cx_Oracle's SessionPool, for 
which we would assume you are using the recipe at 
https://docs.sqlalchemy.org/en/14/dialects/oracle.html#using-cx-oracle-sessionpool
 .


> 
> Thanks,
> Anupama
> 
> 
> 

> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/66a43491-e94b-4b9c-a2ff-6e4ec8ee2cccn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/66a43491-e94b-4b9c-a2ff-6e4ec8ee2cccn%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/c60f7ea3-a28d-4a51-8189-53ef8a17baec%40www.fastmail.com.

Reply via email to