]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add test support for merge_frozen_result
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2021 14:40:14 +0000 (10:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2021 14:41:00 +0000 (10:41 -0400)
Fixed regression where the :func:`_orm.merge_frozen_result` function relied
upon by the dogpile.caching example was not included in tests and began
failing due to incorrect internal arguments.

Fixes: #6211
Change-Id: I0b53d0f569c817994ad4827a3ddb1626fd2d082f

doc/build/changelog/unreleased_14/6211.rst [new file with mode: 0644]
lib/sqlalchemy/orm/loading.py
test/orm/test_loading.py

diff --git a/doc/build/changelog/unreleased_14/6211.rst b/doc/build/changelog/unreleased_14/6211.rst
new file mode 100644 (file)
index 0000000..599b865
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, orm, regression
+    :tickets: 6211
+
+    Fixed regression where the :func:`_orm.merge_frozen_result` function relied
+    upon by the dogpile.caching example was not included in tests and began
+    failing due to incorrect internal arguments.
index 9dcaca0ea0b51ea9d3fc58805bb1fbbc49aa5f42..0dc92daf5bbe0941aa830e16dcd4173090d06ec5 100644 (file)
@@ -201,7 +201,7 @@ def merge_frozen_result(session, statement, frozen_result, load=True):
         session._autoflush()
 
     ctx = querycontext.ORMSelectCompileState._create_entities_collection(
-        statement
+        statement, legacy=False
     )
 
     autoflush = session.autoflush
@@ -262,7 +262,7 @@ def merge_result(query, iterator, load=True):
         frozen_result = None
 
     ctx = querycontext.ORMSelectCompileState._create_entities_collection(
-        query, True
+        query, legacy=True
     )
 
     autoflush = session.autoflush
index e15dbb09f3adda58dd48c84f5ca99834af410177..84fb4975db22a4f1e1c062ff6bb0ac7de904adcc 100644 (file)
@@ -127,6 +127,15 @@ class MergeResultTest(_fixtures.FixtureTest):
         it = loading.merge_result(q, collection)
         eq_([x.id for x in it], [1, 2, 7, 8])
 
+    def test_single_entity_frozen(self):
+        s = fixture_session()
+        User = self.classes.User
+
+        stmt = select(User).where(User.id.in_([7, 8, 9])).order_by(User.id)
+        result = s.execute(stmt)
+        it = loading.merge_frozen_result(s, stmt, result.freeze())
+        eq_([x.id for x in it().scalars()], [7, 8, 9])
+
     def test_single_column(self):
         User = self.classes.User
 
@@ -137,6 +146,16 @@ class MergeResultTest(_fixtures.FixtureTest):
         it = loading.merge_result(q, collection)
         eq_(list(it), [(1,), (2,), (7,), (8,)])
 
+    def test_single_column_frozen(self):
+        User = self.classes.User
+
+        s = fixture_session()
+
+        stmt = select(User.id).where(User.id.in_([7, 8, 9])).order_by(User.id)
+        result = s.execute(stmt)
+        it = loading.merge_frozen_result(s, stmt, result.freeze())
+        eq_([x.id for x in it()], [7, 8, 9])
+
     def test_entity_col_mix_plain_tuple(self):
         s, (u1, u2, u3, u4) = self._fixture()
         User = self.classes.User
@@ -148,6 +167,22 @@ class MergeResultTest(_fixtures.FixtureTest):
         eq_([(x.id, y) for x, y in it], [(1, 1), (2, 2), (7, 7), (8, 8)])
         eq_(list(it[0]._mapping.keys()), ["User", "id"])
 
+    def test_entity_col_mix_plain_tuple_frozen(self):
+        s = fixture_session()
+        User = self.classes.User
+
+        stmt = (
+            select(User, User.id)
+            .where(User.id.in_([7, 8, 9]))
+            .order_by(User.id)
+        )
+        result = s.execute(stmt)
+
+        it = loading.merge_frozen_result(s, stmt, result.freeze())
+        it = list(it())
+        eq_([(x.id, y) for x, y in it], [(7, 7), (8, 8), (9, 9)])
+        eq_(list(it[0]._mapping.keys()), ["User", "id"])
+
     def test_entity_col_mix_keyed_tuple(self):
         s, (u1, u2, u3, u4) = self._fixture()
         User = self.classes.User