]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add warning for empty and_ and or_
authorFederico Caselli <cfederico87@gmail.com>
Sun, 29 Dec 2019 11:56:55 +0000 (12:56 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Sun, 29 Dec 2019 11:56:55 +0000 (12:56 +0100)
.gitignore
lib/sqlalchemy/sql/elements.py
test/sql/test_operators.py

index 087085e50e130e9f97e945596026f9253d3b7a54..b5c9a8229af2e595c146370bdad8ebfa613fdf07 100644 (file)
@@ -32,3 +32,7 @@ test/test_schema.db
 *test_schema.db
 .idea
 /Pipfile*
+/.pytest_cache/
+/pip-wheel-metadata/
+/.vscode/
+/.ipynb_checkpoints/
index 7d857d4feba895653cbbc59d2e9b4678f820845d..83f3c8d310dd53c28bf6aebc8abe37a3d4b8810e 100644 (file)
@@ -2119,6 +2119,15 @@ class BooleanClauseList(ClauseList, ColumnElement):
             coercions.expect(roles.WhereHavingRole, clause)
             for clause in util.coerce_generator_arg(clauses)
         ]
+
+        if len(clauses) == 0:
+            util.warn_deprecated(
+                "Calling %s without any argument is deprecated singe version "
+                "1.4 since it can produce ambiguous behaviour. A future "
+                "version of sqlalchemy will raise an exception in this case"
+                % operator.__name__
+            )
+
         for clause in clauses:
 
             if isinstance(clause, continue_on):
index aa56d0b6b30ab81c7f6dbc7fcc498f6fef168b93..66501256638835b2ca4b646bf468edbf5733e96a 100644 (file)
@@ -50,7 +50,9 @@ from sqlalchemy.sql.expression import tuple_
 from sqlalchemy.sql.expression import UnaryExpression
 from sqlalchemy.sql.expression import union
 from sqlalchemy.testing import assert_raises_message
+from sqlalchemy.testing import combinations
 from sqlalchemy.testing import eq_
+from sqlalchemy.testing import expect_deprecated
 from sqlalchemy.testing import expect_warnings
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing import is_
@@ -1152,6 +1154,16 @@ class ConjunctionTest(fixtures.TestBase, testing.AssertsCompiledSQL):
 
         self.assert_compile(or_(True, False), "true")
 
+    @combinations(and_, or_)
+    def test_empty_clauses(self, op):
+        with expect_deprecated(
+            "Calling %s without any argument is deprecated singe version "
+            "1.4 since it can produce ambiguous behaviour. A future "
+            "version of sqlalchemy will raise an exception in this case"
+            % op.__name__
+        ):
+            op()
+
 
 class OperatorPrecedenceTest(fixtures.TestBase, testing.AssertsCompiledSQL):
     __dialect__ = "default"