> On Nov 7, 2014, at 5:06 AM, Chris Withers <ch...@simplistix.co.uk> wrote:
> 
> Hello,
> 
> So, short version: if I need a raw DBAPI connection and I have a SQLAlchemy 
> Session, what's the correct way to manage that raw connection if I get it 
> using session.connection().connection?
> 
> Versions:
> 
> Postgres 9.2
> SQLAlchemy 0.8.2
> 
> Background:
> 
> I want to create a DataFrame using pandas.io.sql, but this requires a raw 
> DBAPI connection while the rest of my app uses SQLAlchemy sessions. I bashed 
> this in ipython notebook and ended up using session.connection().connection 
> to get the raw connection.
> 
> Now, I'm abstracting some of my notebook experiments into library functions, 
> and I found that unit testing a function that uses 
> session.connection().connection causes a bunch of my other tests to fail even 
> though all of my tests do a session.rollback() as part of the teardown.
> 
> What's the right way to get a raw connection? If it's 
> session.connection().connection, what book-keeping do I need to do to stop 
> stuff done in that connection not being rolled back by session.rollback()?
> 
> Side question: if session.connection() creates a new connection, how is stuff 
> done in that connection not being isolate from stuff done in the session?


session.connection().connection is the same connection that session.rollback() 
will be referring towards.   though when you have that DBAPI connection (it is 
in fact still wrapped by ConnectionFairy), you shouldn’t call commit() or 
rollback() on that connection itself.

session.connection() doesn’t necessarily create a “new” connection, it returns 
“the connection that this Session is currently using”, and if there isn’t one, 
it creates it.

I don’t know your problem yet, you need to dig some more.   maybe try 
StaticPool  / AssertionPool to narrow it down?


-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to