From: Mike Bayer Date: Mon, 16 May 2016 14:32:07 +0000 (-0400) Subject: Accommodate "callable" bound param in evaluator X-Git-Tag: rel_1_1_0b1~42^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a51ab916622dd016ce51d6be0969112817cc42ad;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Accommodate "callable" bound param in evaluator 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 --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index 30f8fb73e0..f40c0a4848 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,15 @@ .. 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 diff --git a/lib/sqlalchemy/orm/evaluator.py b/lib/sqlalchemy/orm/evaluator.py index 534e7fa8f1..6b5da12d99 100644 --- a/lib/sqlalchemy/orm/evaluator.py +++ b/lib/sqlalchemy/orm/evaluator.py @@ -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 diff --git a/test/orm/test_evaluator.py b/test/orm/test_evaluator.py index bafe17b2c2..9aae8dd34c 100644 --- a/test/orm/test_evaluator.py +++ b/test/orm/test_evaluator.py @@ -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