diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-02 21:43:53 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-02 21:47:01 -0500 |
commit | 43cf4a9e5d66946a6a982ab3e1e513bb426eb35b (patch) | |
tree | 0a5668a56cf3e1de2488455aed076941b5b7f15c /lib/sqlalchemy/ext/asyncio/events.py | |
parent | 3fd1a52794c5463854fe36cbe97595d8489bbf62 (diff) | |
download | sqlalchemy-43cf4a9e5d66946a6a982ab3e1e513bb426eb35b.tar.gz |
improve error raise for dialect/pool events w/ async engine
Fixed issues where a descriptive error message was not raised for some
classes of event listening with an async engine, which should instead be a
sync engine instance.
Change-Id: I00b9f4fe9373ef5fd5464fac10651cc4024f648e
Diffstat (limited to 'lib/sqlalchemy/ext/asyncio/events.py')
-rw-r--r-- | lib/sqlalchemy/ext/asyncio/events.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ext/asyncio/events.py b/lib/sqlalchemy/ext/asyncio/events.py index a059b93e6..c5d5e0126 100644 --- a/lib/sqlalchemy/ext/asyncio/events.py +++ b/lib/sqlalchemy/ext/asyncio/events.py @@ -16,21 +16,29 @@ class AsyncConnectionEvents(engine_event.ConnectionEvents): _dispatch_target = AsyncConnectable @classmethod - def _listen(cls, event_key, retval=False): + def _no_async_engine_events(cls): raise NotImplementedError( "asynchronous events are not implemented at this time. Apply " "synchronous listeners to the AsyncEngine.sync_engine or " "AsyncConnection.sync_connection attributes." ) + @classmethod + def _listen(cls, event_key, retval=False): + cls._no_async_engine_events() + class AsyncSessionEvents(orm_event.SessionEvents): _target_class_doc = "SomeSession" _dispatch_target = AsyncSession @classmethod - def _listen(cls, event_key, retval=False): + def _no_async_engine_events(cls): raise NotImplementedError( "asynchronous events are not implemented at this time. Apply " "synchronous listeners to the AsyncSession.sync_session." ) + + @classmethod + def _listen(cls, event_key, retval=False): + cls._no_async_engine_events() |