Re: [sqlalchemy] Asymmetry between engine.begin() and connection.begin()

2016-02-24 Thread Jonathan Beluch
Wonderful, thanks. On Wednesday, February 24, 2016 at 7:50:53 AM UTC-7, Mike Bayer wrote: > > get the connectable first: > > connection = engine_or_connection.connect() > > then do your context manager from that. > > the connection returned, if engine_or_connection is already a > Connection,

Re: [sqlalchemy] Asymmetry between engine.begin() and connection.begin()

2016-02-24 Thread Mike Bayer
get the connectable first: connection = engine_or_connection.connect() then do your context manager from that. the connection returned, if engine_or_connection is already a Connection, is "branched", meaning it is safe to call close() on it without affecting the original. So fully: with

[sqlalchemy] Asymmetry between engine.begin() and connection.begin()

2016-02-23 Thread Jonathan Beluch
Is there a better way of doing this? Basically I have a function that takes a connectable (engine or connection) and I want to start a transaction. However I can't just call .begin() because it could return a Transaction or a Connection depending on what was passed in and I need a connection.