summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/changelog_10.rst9
-rw-r--r--lib/sqlalchemy/orm/evaluator.py5
-rw-r--r--test/orm/test_evaluator.py14
3 files changed, 26 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index 972e808df..f4bf10954 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -19,6 +19,15 @@
: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 534e7fa8f..6b5da12d9 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 bafe17b2c..9aae8dd34 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