summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-04-07 14:15:43 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-04-16 13:35:55 -0400
commit2f617f56f2acdce00b88f746c403cf5ed66d4d27 (patch)
tree0962f2c43c1a361135ecdab933167fa0963ae58a /lib/sqlalchemy/orm/session.py
parentbd303b10e2bf69169f07447c7272fc71ac931f10 (diff)
downloadsqlalchemy-2f617f56f2acdce00b88f746c403cf5ed66d4d27.tar.gz
Create initial 2.0 engine implementation
Implemented the SQLAlchemy 2 :func:`.future.create_engine` function which is used for forwards compatibility with SQLAlchemy 2. This engine features always-transactional behavior with autobegin. Allow execution options per statement execution. This includes that the before_execute() and after_execute() events now accept an additional dictionary with these options, empty if not passed; a legacy event decorator is added for backwards compatibility which now also emits a deprecation warning. Add some basic tests for execution, transactions, and the new result object. Build out on a new testing fixture that swaps in the future engine completely to start with. Change-Id: I70e7338bb3f0ce22d2f702537d94bb249bd9fb0a Fixes: #4644
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r--lib/sqlalchemy/orm/session.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 534d67530..4ca715dd3 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -447,7 +447,10 @@ class SessionTransaction(object):
elif self.nested:
transaction = conn.begin_nested()
else:
- transaction = conn.begin()
+ if conn._is_future and conn.in_transaction():
+ transaction = conn._transaction
+ else:
+ transaction = conn.begin()
except:
# connection will not not be associated with this Session;
# close it immediately so that it isn't closed under GC
@@ -455,10 +458,13 @@ class SessionTransaction(object):
conn.close()
raise
else:
+ bind_is_connection = isinstance(bind, engine.Connection)
+
self._connections[conn] = self._connections[conn.engine] = (
conn,
transaction,
- conn is not bind,
+ not bind_is_connection or not conn._is_future,
+ not bind_is_connection,
)
self.session.dispatch.after_begin(self.session, self, conn)
return conn
@@ -509,8 +515,11 @@ class SessionTransaction(object):
self._prepare_impl()
if self._parent is None or self.nested:
- for t in set(self._connections.values()):
- t[1].commit()
+ for conn, trans, should_commit, autoclose in set(
+ self._connections.values()
+ ):
+ if should_commit:
+ trans.commit()
self._state = COMMITTED
self.session.dispatch.after_commit(self.session)
@@ -579,7 +588,7 @@ class SessionTransaction(object):
def close(self, invalidate=False):
self.session._transaction = self._parent
if self._parent is None:
- for connection, transaction, autoclose in set(
+ for connection, transaction, should_commit, autoclose in set(
self._connections.values()
):
if invalidate: