diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-06 22:56:14 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-07 15:59:59 -0500 |
commit | b45aa7c4062bafae23286c3069571c2596aabc66 (patch) | |
tree | 12d496c61ab71e02ca0fa1c785ee8b34d577b73a /lib/sqlalchemy/ext/asyncio/base.py | |
parent | 7f92fdbd8ec479a61c53c11921ce0688ad4dd94b (diff) | |
download | sqlalchemy-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/base.py')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/base.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/base.py b/lib/sqlalchemy/ext/asyncio/base.py index 051f9e21a..fa8c5006e 100644 --- a/lib/sqlalchemy/ext/asyncio/base.py +++ b/lib/sqlalchemy/ext/asyncio/base.py @@ -23,3 +23,20 @@ class StartableContext(abc.ABC): "%s context has not been started and object has not been awaited." % (self.__class__.__name__) ) + + +class ProxyComparable: + def __hash__(self): + return id(self) + + def __eq__(self, other): + return ( + isinstance(other, self.__class__) + and self._proxied == other._proxied + ) + + def __ne__(self, other): + return ( + not isinstance(other, self.__class__) + or self._proxied != other._proxied + ) |