diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2021-08-30 19:36:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-08-30 19:36:40 +0000 |
commit | fb874f97fab798eea76f9732a31bb9332877d00e (patch) | |
tree | 7fce5c30db89ebbf5ddc212be44b83275bda9881 /lib/sqlalchemy/ext/asyncio | |
parent | 916bd20b6d1e7c153d334c31cf0882f502e3815e (diff) | |
parent | 1798c3cf1c407ba2a05855e97ae39997f213084d (diff) | |
download | sqlalchemy-fb874f97fab798eea76f9732a31bb9332877d00e.tar.gz |
Merge "Improve error message when inspecting async proxies"
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/base.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/engine.py | 23 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/base.py b/lib/sqlalchemy/ext/asyncio/base.py index 3f2c084f4..3f77f5500 100644 --- a/lib/sqlalchemy/ext/asyncio/base.py +++ b/lib/sqlalchemy/ext/asyncio/base.py @@ -8,6 +8,7 @@ from . import exc as async_exc class ReversibleProxy: # weakref.ref(async proxy object) -> weakref.ref(sync proxied object) _proxy_objects = {} + __slots__ = ("__weakref__",) def _assign_proxied(self, target): if target is not None: @@ -46,6 +47,8 @@ class ReversibleProxy: class StartableContext(abc.ABC): + __slots__ = () + @abc.abstractmethod async def start(self, is_ctxmanager=False): pass @@ -68,6 +71,8 @@ class StartableContext(abc.ABC): class ProxyComparable(ReversibleProxy): + __slots__ = () + def __hash__(self): return id(self) diff --git a/lib/sqlalchemy/ext/asyncio/engine.py b/lib/sqlalchemy/ext/asyncio/engine.py index f5c3bdca4..5a692ffb1 100644 --- a/lib/sqlalchemy/ext/asyncio/engine.py +++ b/lib/sqlalchemy/ext/asyncio/engine.py @@ -9,6 +9,7 @@ from .base import ProxyComparable from .base import StartableContext from .result import AsyncResult from ... import exc +from ... import inspection from ... import util from ...engine import create_engine as _create_engine from ...engine.base import NestedTransaction @@ -80,6 +81,7 @@ class AsyncConnection(ProxyComparable, StartableContext, AsyncConnectable): # create a new AsyncConnection that matches this one given only the # "sync" elements. __slots__ = ( + "engine", "sync_engine", "sync_connection", ) @@ -709,3 +711,24 @@ def _get_sync_engine_or_connection(async_engine): raise exc.ArgumentError( "AsyncEngine expected, got %r" % async_engine ) from e + + +@inspection._inspects(AsyncConnection) +def _no_insp_for_async_conn_yet(subject): + raise exc.NoInspectionAvailable( + "Inspection on an AsyncConnection is currently not supported. " + "Please use ``run_sync`` to pass a callable where it's possible " + "to call ``inspect`` on the passed connection.", + code="xd3s", + ) + + +@inspection._inspects(AsyncEngine) +def _no_insp_for_async_engine_xyet(subject): + raise exc.NoInspectionAvailable( + "Inspection on an AsyncEngine is currently not supported. " + "Please obtain a connection then use ``conn.run_sync`` to pass a " + "callable where it's possible to call ``inspect`` on the " + "passed connection.", + code="xd3s", + ) |