diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-03-21 10:57:40 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-03-21 10:57:40 -0400 |
| commit | 07a4b6cbcda6e6ee6e67893c5a5d2fd01e5f125f (patch) | |
| tree | a28aac49f1f8fd7aef5ae3ed85a2bd9ce98978d1 /lib/sqlalchemy/sql/elements.py | |
| parent | 732c613eeb890e7b7cbd04750468dac584151a31 (diff) | |
| download | sqlalchemy-07a4b6cbcda6e6ee6e67893c5a5d2fd01e5f125f.tar.gz | |
- Fixed bug where the negation of an EXISTS expression would not
be properly typed as boolean in the result, and also would fail to be
anonymously aliased in a SELECT list as is the case with a
non-negated EXISTS construct.
fixes #3682
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 8256900f9..00c2c37ba 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -646,6 +646,9 @@ 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() @@ -2766,6 +2769,13 @@ class UnaryExpression(ColumnElement): modifier=self.modifier, type_=self.type, wraps_column_expression=self.wraps_column_expression) + elif self.type._type_affinity is type_api.BOOLEANTYPE._type_affinity: + return UnaryExpression( + self.self_group(against=operators.inv), + operator=operators.inv, + type_=type_api.BOOLEANTYPE, + wraps_column_expression=self.wraps_column_expression, + negate=None) else: return ClauseElement._negate(self) @@ -2875,6 +2885,9 @@ 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() |
