]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Accept **kw in annotated._clone() method
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 25 Mar 2021 12:40:16 +0000 (08:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 25 Mar 2021 12:45:32 +0000 (08:45 -0400)
Fixed bug where combinations of the new "relationship with criteria"
feature could fail in conjunction with features that make use of the new
"lambda SQL" feature, including loader strategies such as selectinload and
lazyload, for more complicated scenarios such as polymorphic loading.

Fixes: #6131
Change-Id: I915dead6596866ae5fd1a7f593a90bce4b61d1af

doc/build/changelog/unreleased_14/6131.rst [new file with mode: 0644]
lib/sqlalchemy/sql/annotation.py
lib/sqlalchemy/sql/elements.py
test/sql/test_lambdas.py

diff --git a/doc/build/changelog/unreleased_14/6131.rst b/doc/build/changelog/unreleased_14/6131.rst
new file mode 100644 (file)
index 0000000..ceba914
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, orm
+    :tickets: 6131
+
+    Fixed bug where combinations of the new "relationship with criteria"
+    feature could fail in conjunction with features that make use of the new
+    "lambda SQL" feature, including loader strategies such as selectinload and
+    lazyload, for more complicated scenarios such as polymorphic loading.
index 23b5052a9db9d4dbfd2a7d93633546e35424f249..8e5cdf148c754e589c08f182cc03c9f58c59193f 100644 (file)
@@ -199,8 +199,8 @@ class Annotated(object):
     def _constructor(self):
         return self.__element._constructor
 
-    def _clone(self):
-        clone = self.__element._clone()
+    def _clone(self, **kw):
+        clone = self.__element._clone(**kw)
         if clone is self.__element:
             # detect immutable, don't change anything
             return self
index 20c3e899114467b2f2054ad207b14d5612331f55..74e8dceffd99c81b5f469e89d155f9843f40cfa1 100644 (file)
@@ -1493,7 +1493,8 @@ class BindParameter(roles.InElementRole, ColumnElement):
         self.__dict__.update(state)
 
     def __repr__(self):
-        return "BindParameter(%r, %r, type_=%r)" % (
+        return "%s(%r, %r, type_=%r)" % (
+            self.__class__.__name__,
             self.key,
             self.value,
             self.type,
index fcf024182502be157c2a950161498a96b1178af7..24a83c9ee3d2a920a71ba6868496a7aa51e9fb30 100644 (file)
@@ -1453,6 +1453,17 @@ class LambdaElementTest(
         is_(expr1._generate_cache_key().bindparams[0], expr1._resolved.right)
         is_(expr2._generate_cache_key().bindparams[0], expr2._resolved.right)
 
+    def test_cache_key_bindparam_matches_annotations(self):
+        t1 = table("t1", column("q"), column("p"))
+
+        def go():
+            expr = sql_util._deep_annotate((t1.c.q == 5), {"foo": "bar"})
+            stmt = coercions.expect(roles.WhereHavingRole, lambda: expr)
+            return stmt
+
+        self.assert_compile(go(), "t1.q = :q_1", checkparams={"q_1": 5})
+        self.assert_compile(go(), "t1.q = :q_1", checkparams={"q_1": 5})
+
     def test_cache_key_instance_variable_issue_incorrect(self):
         t1 = table("t1", column("q"), column("p"))