]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Accommodate "callable" bound param in evaluator
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 May 2016 14:32:07 +0000 (10:32 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 May 2016 14:32:07 +0000 (10:32 -0400)
Fixed bug in "evaluate" strategy of :meth:`.Query.update` and
:meth:`.Query.delete` which would fail to accommodate a bound
parameter with a "callable" value, as which occurs when filtering
by a many-to-one equality expression along a relationship.

Change-Id: I47758d3f5d8b9ea1a07e23166780d5f3c32b17f1
Fixes: #3700
doc/build/changelog/changelog_10.rst
lib/sqlalchemy/orm/evaluator.py
test/orm/test_evaluator.py

index 30f8fb73e0c5528a8579c8e61448aca9ffa4f7a7..f40c0a4848dd43e8585e5a2ba6bee8a70aeceeae 100644 (file)
 .. changelog::
     :version: 1.0.13
 
+    .. change::
+        :tags: bug, orm
+        :tickets: 3700
+
+        Fixed bug in "evaluate" strategy of :meth:`.Query.update` and
+        :meth:`.Query.delete` which would fail to accommodate a bound
+        parameter with a "callable" value, as which occurs when filtering
+        by a many-to-one equality expression along a relationship.
+
     .. change::
         :tags: bug, postgresql
         :tickets: 3715
index 534e7fa8f1e24d70c6368f9890c13dc5fc81e70e..6b5da12d99e4e8a91aafc18f13da33a2c5b28ad8 100644 (file)
@@ -130,5 +130,8 @@ class EvaluatorCompiler(object):
             (type(clause).__name__, clause.operator))
 
     def visit_bindparam(self, clause):
-        val = clause.value
+        if clause.callable:
+            val = clause.callable()
+        else:
+            val = clause.value
         return lambda obj: val
index bafe17b2c2dda0fda0f1452cb430a543d0293ae5..9aae8dd34c0e33b23fc18b3e59c32d9c1798bb0e 100644 (file)
@@ -1,6 +1,6 @@
 """Evaluating SQL expressions on ORM objects"""
 
-from sqlalchemy import String, Integer
+from sqlalchemy import String, Integer, bindparam
 from sqlalchemy.testing.schema import Table
 from sqlalchemy.testing.schema import Column
 from sqlalchemy.testing import fixtures
@@ -58,6 +58,18 @@ class EvaluateTest(fixtures.MappedTest):
             (User(id=None), None),
         ])
 
+    def test_compare_to_callable_bind(self):
+        User = self.classes.User
+
+        eval_eq(
+            User.name == bindparam('x', callable_=lambda: 'foo'),
+            testcases=[
+                (User(name='foo'), True),
+                (User(name='bar'), False),
+                (User(name=None), None),
+            ]
+        )
+
     def test_compare_to_none(self):
         User = self.classes.User