summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-07-19 10:27:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-07-19 10:27:33 -0400
commit3cfe3fd81d7ce3539633b80c99327767cebd09d5 (patch)
tree16000577833d3c3eb7b69c320cf8a0986f1e0b2d
parent41aead96cdfd581c053a395992e1a3cf0b6a5572 (diff)
downloadsqlalchemy-3cfe3fd81d7ce3539633b80c99327767cebd09d5.tar.gz
- Fixed bug where coersion of literal ``True`` or ``False`` constant
in conjunction with :func:`.and_` or :func:`.or_` would fail with an AttributeError. fixes #3490
-rw-r--r--doc/build/changelog/changelog_10.rst8
-rw-r--r--lib/sqlalchemy/sql/elements.py7
-rw-r--r--test/sql/test_operators.py58
3 files changed, 71 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index c4d9ab448..7dae2bebd 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -20,6 +20,14 @@
.. change::
:tags: bug, sql
+ :tickets: 3490
+
+ Fixed bug where coersion of literal ``True`` or ``False`` constant
+ in conjunction with :func:`.and_` or :func:`.or_` would fail
+ with an AttributeError.
+
+ .. change::
+ :tags: bug, sql
:tickets: 3485
Fixed potential issue where a custom subclass
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 41dfcf147..eb0923e15 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -1847,9 +1847,12 @@ class BooleanClauseList(ClauseList, ColumnElement):
def _construct(cls, operator, continue_on, skip_on, *clauses, **kw):
convert_clauses = []
- clauses = util.coerce_generator_arg(clauses)
+ clauses = [
+ _expression_literal_as_text(clause)
+ for clause in
+ util.coerce_generator_arg(clauses)
+ ]
for clause in clauses:
- clause = _expression_literal_as_text(clause)
if isinstance(clause, continue_on):
continue
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 65d1e3716..bb4cb1bf1 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -825,6 +825,64 @@ class ConjunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL):
"SELECT false AS anon_1, false AS anon_2"
)
+ def test_is_true_literal(self):
+ c = column('x', Boolean)
+ self.assert_compile(
+ c.is_(True),
+ "x IS true"
+ )
+
+ def test_is_false_literal(self):
+ c = column('x', Boolean)
+ self.assert_compile(
+ c.is_(False),
+ "x IS false"
+ )
+
+ def test_and_false_literal_leading(self):
+ self.assert_compile(
+ and_(False, True),
+ "false"
+ )
+
+ self.assert_compile(
+ and_(False, False),
+ "false"
+ )
+
+ def test_and_true_literal_leading(self):
+ self.assert_compile(
+ and_(True, True),
+ "true"
+ )
+
+ self.assert_compile(
+ and_(True, False),
+ "false"
+ )
+
+ def test_or_false_literal_leading(self):
+ self.assert_compile(
+ or_(False, True),
+ "true"
+ )
+
+ self.assert_compile(
+ or_(False, False),
+ "false"
+ )
+
+ def test_or_true_literal_leading(self):
+ self.assert_compile(
+ or_(True, True),
+ "true"
+ )
+
+ self.assert_compile(
+ or_(True, False),
+ "true"
+ )
+
class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = 'default'