summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/asyncio/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-01-06 22:56:14 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-07 15:59:59 -0500
commitb45aa7c4062bafae23286c3069571c2596aabc66 (patch)
tree12d496c61ab71e02ca0fa1c785ee8b34d577b73a /lib/sqlalchemy/ext/asyncio/session.py
parent7f92fdbd8ec479a61c53c11921ce0688ad4dd94b (diff)
downloadsqlalchemy-b45aa7c4062bafae23286c3069571c2596aabc66.tar.gz
Implement connection binding for AsyncSession
Implemented "connection-binding" for :class:`.AsyncSession`, the ability to pass an :class:`.AsyncConnection` to create an :class:`.AsyncSession`. Previously, this use case was not implemented and would use the associated engine when the connection were passed. This fixes the issue where the "join a session to an external transaction" use case would not work correctly for the :class:`.AsyncSession`. Additionally, added methods :meth:`.AsyncConnection.in_transaction`, :meth:`.AsyncConnection.in_nested_transaction`, :meth:`.AsyncConnection.get_transaction`. The :class:`.AsyncEngine`, :class:`.AsyncConnection` and :class:`.AsyncTransaction` objects may be compared using Python ``==`` or ``!=``, which will compare the two given objects based on the "sync" object they are proxying towards. This is useful as there are cases particularly for :class:`.AsyncTransaction` where multiple instances of :class:`.AsyncTransaction` can be proxying towards the same sync :class:`_engine.Transaction`, and are actually equivalent. The :meth:`.AsyncConnection.get_transaction` method will currently return a new proxying :class:`.AsyncTransaction` each time as the :class:`.AsyncTransaction` is not otherwise statefully associated with its originating :class:`.AsyncConnection`. Fixes: #5811 Change-Id: I5a3a6b2f088541eee7b0e0f393510e61bc9f986b
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/session.py')
-rw-r--r--lib/sqlalchemy/ext/asyncio/session.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/session.py b/lib/sqlalchemy/ext/asyncio/session.py
index bac2aa44b..9a8284e64 100644
--- a/lib/sqlalchemy/ext/asyncio/session.py
+++ b/lib/sqlalchemy/ext/asyncio/session.py
@@ -75,12 +75,13 @@ class AsyncSession:
kw["future"] = True
if bind:
self.bind = engine
- bind = engine._get_sync_engine(bind)
+ bind = engine._get_sync_engine_or_connection(bind)
if binds:
self.binds = binds
binds = {
- key: engine._get_sync_engine(b) for key, b in binds.items()
+ key: engine._get_sync_engine_or_connection(b)
+ for key, b in binds.items()
}
self.sync_session = self._proxied = Session(