On Tue, Aug 28, 2018 at 5:53 PM Simon King <si...@simonking.org.uk> wrote:
>
> On Tue, Aug 28, 2018 at 4:32 PM 'Brian DeRocher' via sqlalchemy
> <sqlalchemy@googlegroups.com> wrote:
> >
> > Hey all,
> >
> > I'm writing some automated tests for some legacy python code using a 
> > psycopg2 connection.  I'd like to check data in the database by using 
> > SQLAlchemy.  I rollback the database transaction after each test in 
> > tearDown().
> >
> > The problem is my SQLAlchemy connection doesn't see the database updates.  
> > At first I thought they weren't using the same connection, but they are.  
> > I'm using create_engine(..., creator=get_conn).
> >
> > The problem appears to be that DefaultDialect is rolling back the 
> > transaction.  See sqlalchemy/engine/default.py line 167.  I had to review 
> > PG logs to spot this as it's not logged.
> >
> > self.do_rollback(connection.connection)
> >
> > Is this line really needed?  What would it be rolling back?  Can it be 
> > avoided?  When I disable this line of code, the transaction continues and 
> > sqlalchemy can see the updates from psyopg2.
> >
> > I've attached a demo file.
> >
>
> I haven't tried to run your code, but the usual way to connect a
> session to an existing connection is to bind the session directly to
> the connection:
>
> http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites
>
> Would that work for your situation?
>
> Hope that helps,
>
> Simon

Sorry, I realised just after I pressed Send that you have a
DBAPI-level connection rather than an SQLAlchemy connection, so my
suggestion doesn't really help...

For what it's worth, the "do_rollback" was apparently added here:

https://bitbucket.org/zzzeek/sqlalchemy/commits/39fd3442e306f9c2981c347ab2487921f3948a61#chg-lib/sqlalchemy/engine/default.py

Simon

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

Reply via email to