From c6f54ae434b40f0ddfce468d29663014ca5fc135 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 31 May 2013 11:52:31 -0400 Subject: [PATCH] Fixed a regression caused by [ticket:2682] whereby the evaluation invoked by :meth:`.Query.update` and :meth:`.Query.delete` would hit upon unsupported ``True`` and ``False`` symbols which now appear due to the usage of ``IS``. [ticket:2737] Conflicts: doc/build/changelog/changelog_08.rst --- doc/build/changelog/changelog_08.rst | 9 +++++++++ lib/sqlalchemy/orm/evaluator.py | 6 ++++++ test/orm/test_evaluator.py | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index d10a3da285..211668867e 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -17,6 +17,15 @@ :meth:`.Query.select_entity_from` method as appropriate. See the 0.9 migration guide for details. + .. change:: + :tags: bug, orm + :tickets: 2737 + + Fixed a regression caused by :ticket:`2682` whereby the + evaluation invoked by :meth:`.Query.update` and :meth:`.Query.delete` + would hit upon unsupported ``True`` and ``False`` symbols + which now appear due to the usage of ``IS``. + .. change:: :tags: bug, postgresql :tickets: 2735 diff --git a/lib/sqlalchemy/orm/evaluator.py b/lib/sqlalchemy/orm/evaluator.py index 0844e2f72b..ba59e50716 100644 --- a/lib/sqlalchemy/orm/evaluator.py +++ b/lib/sqlalchemy/orm/evaluator.py @@ -40,6 +40,12 @@ class EvaluatorCompiler(object): def visit_null(self, clause): return lambda obj: None + def visit_false(self, clause): + return lambda obj: False + + def visit_true(self, clause): + return lambda obj: True + def visit_column(self, clause): if 'parentmapper' in clause._annotations: key = clause._annotations['parentmapper'].\ diff --git a/test/orm/test_evaluator.py b/test/orm/test_evaluator.py index 4678100ebd..2570f76503 100644 --- a/test/orm/test_evaluator.py +++ b/test/orm/test_evaluator.py @@ -62,6 +62,23 @@ class EvaluateTest(fixtures.MappedTest): (User(name=None), True), ]) + def test_true_false(self): + User = self.classes.User + + eval_eq(User.name == False, testcases=[ + (User(name='foo'), False), + (User(name=True), False), + (User(name=False), True), + ] + ) + + eval_eq(User.name == True, testcases=[ + (User(name='foo'), False), + (User(name=True), True), + (User(name=False), False), + ] + ) + def test_boolean_ops(self): User = self.classes.User -- 2.47.3