diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-18 09:40:03 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-18 13:41:10 -0400 |
commit | e9737a9d9b1becc7dba1661f17b247db3213c511 (patch) | |
tree | 16adb6ff444c1559e32a3a778b9328d50415b453 /lib/sqlalchemy/sql/elements.py | |
parent | 6758a459597e5221607a81a693bd98352bb1c94f (diff) | |
download | sqlalchemy-e9737a9d9b1becc7dba1661f17b247db3213c511.tar.gz |
negate True/False separately from other elements
Fixed issue where double negation of a boolean column wouldn't reset
the "NOT" operator.
Fixes: #4618
Change-Id: Ica280a0d6b5b0870aa2d05c4d059a1e559e6b12a
(cherry picked from commit 18f25f50353d9736e6638266585b2cb3ef7b0ea4)
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index a4623128f..b0d0feff5 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -691,9 +691,6 @@ class ColumnElement(operators.ColumnOperators, ClauseElement): def _negate(self): if self.type._type_affinity is type_api.BOOLEANTYPE._type_affinity: - # TODO: see the note in AsBoolean that it seems to assume - # the element is the True_() / False_() constant, so this - # is too broad return AsBoolean(self, operators.isfalse, operators.istrue) else: return super(ColumnElement, self)._negate() @@ -3035,10 +3032,10 @@ class AsBoolean(UnaryExpression): return self def _negate(self): - # TODO: this assumes the element is the True_() or False_() - # object, but this assumption isn't enforced and - # ColumnElement._negate() can send any number of expressions here - return self.element._negate() + if isinstance(self.element, (True_, False_)): + return self.element._negate() + else: + return AsBoolean(self.element, self.negate, self.operator) class BinaryExpression(ColumnElement): |