Joe Biggert
2018-01-16 17:33:41 UTC
We've got some legacy code using SQLAlchemy 0.8 (we're actively looking to
upgrade to the latest) and we've got a wrapper around our requests that
basically looks like this:
try:
# work
Session.commit()
except:
Session.rollback()
raise
finally:
Session.remove()
if Session.bind:
Session.bind.pool.dispose()
Now there's a couple flavors of that using local session but considering we
are using scoped_session, that probably doesn't make a big difference.
Please correct me if I'm wrong, but the workflow goes like this: we're
doing whatever work we have then committing the transaction... if an
exception occurs, we're rolling back that transaction... and lastly, we're
doing a remove() which rollbacks any underlying transaction and then
releases the connection(s) back to the connection pool
per http://docs.sqlalchemy.org/en/latest/orm/contextual.html#contextual-thread-local-sessions.
The last part is the one that I'm confused about whether it's intended
usage. Reading the documentation on the dipose()
method, http://docs.sqlalchemy.org/en/latest/core/pooling.html#sqlalchemy.pool.Pool.dispose,
it leads me to believe our usage of this method isn't needed... and if
after we're done with them because we've experienced some areas where
connections are left open and idle in transaction. I've been searching
around and haven't found anywhere suggesting this function is what should
be used... this
link, https://groups.google.com/forum/#!topic/sqlalchemy/09h4az61oXo, also
suggested not to use it for this purpose.
Can anyone clear this up for me? The only thing I can think of is that, in
0.8, something finicky may have been going on so it was recommended at some
time to us this?
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
upgrade to the latest) and we've got a wrapper around our requests that
basically looks like this:
try:
# work
Session.commit()
except:
Session.rollback()
raise
finally:
Session.remove()
if Session.bind:
Session.bind.pool.dispose()
Now there's a couple flavors of that using local session but considering we
are using scoped_session, that probably doesn't make a big difference.
Please correct me if I'm wrong, but the workflow goes like this: we're
doing whatever work we have then committing the transaction... if an
exception occurs, we're rolling back that transaction... and lastly, we're
doing a remove() which rollbacks any underlying transaction and then
releases the connection(s) back to the connection pool
per http://docs.sqlalchemy.org/en/latest/orm/contextual.html#contextual-thread-local-sessions.
The last part is the one that I'm confused about whether it's intended
usage. Reading the documentation on the dipose()
method, http://docs.sqlalchemy.org/en/latest/core/pooling.html#sqlalchemy.pool.Pool.dispose,
it leads me to believe our usage of this method isn't needed... and if
This method leaves the possibility of checked-out connections remaining
open, as it only affects connections that are idle in the pool.
I believe the intent of the usage here is to explicitly close connectionsopen, as it only affects connections that are idle in the pool.
after we're done with them because we've experienced some areas where
connections are left open and idle in transaction. I've been searching
around and haven't found anywhere suggesting this function is what should
be used... this
link, https://groups.google.com/forum/#!topic/sqlalchemy/09h4az61oXo, also
suggested not to use it for this purpose.
Can anyone clear this up for me? The only thing I can think of is that, in
0.8, something finicky may have been going on so it was recommended at some
time to us this?
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.