]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add missing methods added in :ticket:`6991`
authorFederico Caselli <cfederico87@gmail.com>
Tue, 28 Sep 2021 20:58:08 +0000 (22:58 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Tue, 28 Sep 2021 21:11:46 +0000 (23:11 +0200)
to ``scoped_session`` and ``async_scoped_session``.

Fixes: #7103
Change-Id: If80481771d9b428f2403af3862e0479bd069257e

doc/build/changelog/unreleased_14/7103.rst [new file with mode: 0644]
lib/sqlalchemy/ext/asyncio/scoping.py
lib/sqlalchemy/orm/scoping.py
test/ext/asyncio/test_scoping_py3k.py
test/orm/test_scoping.py

diff --git a/doc/build/changelog/unreleased_14/7103.rst b/doc/build/changelog/unreleased_14/7103.rst
new file mode 100644 (file)
index 0000000..2682b04
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug
+    :tickets: 7103
+
+    Add missing methods added in :ticket:`6991` to ``scoped_session`` and
+    ``async_scoped_session``.
index 7fa8cba5cf5e148d8f125da5fccd2545b2d51268..4e7f15c1fdad49ec39f2e421f3c9107319220c7d 100644 (file)
@@ -40,6 +40,9 @@ from ...util import ScopedRegistry
         "refresh",
         "rollback",
         "scalar",
+        "scalars",
+        "stream",
+        "stream_scalars",
     ],
     attributes=[
         "bind",
index 353caa8fef8983255c5cb8a036a6699a6128b8a1..df3012df1e49ef468ac555ec16c97237090e0131 100644 (file)
@@ -105,6 +105,7 @@ class ScopedSessionMixin(object):
         "refresh",
         "rollback",
         "scalar",
+        "scalars",
     ],
     attributes=[
         "bind",
index c2ca73c419b881a14b5fd68ce41168b93943aae7..7eeff566c3700dd8c9b383121b49ccf5b16bb298 100644 (file)
@@ -1,9 +1,12 @@
+from asyncio import current_task
+
 import sqlalchemy as sa
 from sqlalchemy import func
 from sqlalchemy import select
 from sqlalchemy import testing
 from sqlalchemy.ext.asyncio import async_scoped_session
 from sqlalchemy.ext.asyncio import AsyncSession as _AsyncSession
+from sqlalchemy.orm import sessionmaker
 from sqlalchemy.testing import async_test
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import is_
@@ -44,3 +47,32 @@ class AsyncScopedSessionTest(AsyncFixture):
             await AsyncSession.delete(u1)
             await AsyncSession.flush()
             eq_(await conn.scalar(stmt), 0)
+
+    def test_attributes(self, async_engine):
+        expected = [
+            name
+            for cls in _AsyncSession.mro()
+            for name in vars(cls)
+            if not name.startswith("_")
+        ]
+
+        ignore_list = {
+            "dispatch",
+            "sync_session_class",
+            "run_sync",
+            "get_transaction",
+            "get_nested_transaction",
+            "in_transaction",
+            "in_nested_transaction",
+        }
+
+        SM = async_scoped_session(
+            sessionmaker(async_engine, class_=_AsyncSession), current_task
+        )
+
+        missing = [
+            name
+            for name in expected
+            if not hasattr(SM, name) and name not in ignore_list
+        ]
+        eq_(missing, [])
index ad4ab55a284b07d3a38f9c9097a26bf4e97ecda2..9604adc6c5930bb678592bab4c2ead62b7511a7a 100644 (file)
@@ -209,3 +209,35 @@ class ScopedSessionTest(fixtures.MappedTest):
         ss = scoped_session(sessionmaker(testing.db, class_=MySession))
 
         is_(ss.get_bind(), testing.db)
+
+    def test_attributes(self):
+        expected = [
+            name
+            for cls in Session.mro()
+            for name in vars(cls)
+            if not name.startswith("_")
+        ]
+
+        ignore_list = {
+            "connection_callable",
+            "transaction",
+            "in_transaction",
+            "in_nested_transaction",
+            "get_transaction",
+            "get_nested_transaction",
+            "prepare",
+            "invalidate",
+            "bind_mapper",
+            "bind_table",
+            "enable_relationship_loading",
+            "dispatch",
+        }
+
+        SM = scoped_session(sa.orm.sessionmaker(testing.db))
+
+        missing = [
+            name
+            for name in expected
+            if not hasattr(SM, name) and name not in ignore_list
+        ]
+        eq_(missing, [])