summaryrefslogtreecommitdiff
path: root/test/ext/asyncio/test_session_py3k.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-02-04 09:04:49 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-02-04 12:49:24 -0500
commitfaa9ef2cff53bde291df5ac3b5c4ed8f665ecd8c (patch)
treee33df958d54550f88909793d8a4bdf9c3e655b3b /test/ext/asyncio/test_session_py3k.py
parentb93cef577d6471aa18a6b1cde8a97598fc837377 (diff)
downloadsqlalchemy-faa9ef2cff53bde291df5ac3b5c4ed8f665ecd8c.tar.gz
ensure exception raised for all stream w/ sync result
Fixed issue where the :meth:`_asyncio.AsyncSession.execute` method failed to raise an informative exception if the ``stream_results`` execution option were used, which is incompatible with a sync-style :class:`_result.Result` object. An exception is now raised in this scenario in the same way one is already raised when using ``stream_results`` in conjunction with the :meth:`_asyncio.AsyncConnection.execute` method. Additionally, for improved stability with state-sensitive dialects such as asyncmy, the cursor is now closed when this error condition is raised; previously with the asyncmy dialect, the connection would go into an invalid state with unconsumed server side results remaining. Fixes: #7667 Change-Id: I6eb7affe08584889b57423a90258295f8b7085dc
Diffstat (limited to 'test/ext/asyncio/test_session_py3k.py')
-rw-r--r--test/ext/asyncio/test_session_py3k.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ext/asyncio/test_session_py3k.py b/test/ext/asyncio/test_session_py3k.py
index bcaea05e5..f04b87f37 100644
--- a/test/ext/asyncio/test_session_py3k.py
+++ b/test/ext/asyncio/test_session_py3k.py
@@ -11,6 +11,7 @@ from sqlalchemy import testing
from sqlalchemy import update
from sqlalchemy.ext.asyncio import async_object_session
from sqlalchemy.ext.asyncio import AsyncSession
+from sqlalchemy.ext.asyncio import exc as async_exc
from sqlalchemy.ext.asyncio.base import ReversibleProxy
from sqlalchemy.orm import relationship
from sqlalchemy.orm import selectinload
@@ -19,6 +20,7 @@ from sqlalchemy.orm import sessionmaker
from sqlalchemy.testing import async_test
from sqlalchemy.testing import engines
from sqlalchemy.testing import eq_
+from sqlalchemy.testing import expect_raises_message
from sqlalchemy.testing import is_
from sqlalchemy.testing import is_true
from sqlalchemy.testing import mock
@@ -165,6 +167,28 @@ class AsyncSessionQueryTest(AsyncFixture):
],
)
+ @testing.combinations("statement", "execute", argnames="location")
+ @async_test
+ async def test_no_ss_cursor_w_execute(self, async_session, location):
+ User = self.classes.User
+
+ stmt = select(User)
+ if location == "statement":
+ stmt = stmt.execution_options(stream_results=True)
+
+ with expect_raises_message(
+ async_exc.AsyncMethodRequired,
+ r"Can't use the AsyncSession.execute\(\) method with a "
+ r"server-side cursor. Use the AsyncSession.stream\(\) "
+ r"method for an async streaming result set.",
+ ):
+ if location == "execute":
+ await async_session.execute(
+ stmt, execution_options={"stream_results": True}
+ )
+ else:
+ await async_session.execute(stmt)
+
class AsyncSessionTransactionTest(AsyncFixture):
run_inserts = None