From: Federico Caselli Date: Sun, 29 Dec 2019 11:56:55 +0000 (+0100) Subject: add warning for empty and_ and or_ X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2228012a659f1205964f51daedb8957a5e756576;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add warning for empty and_ and or_ --- diff --git a/.gitignore b/.gitignore index 087085e50e..b5c9a8229a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ test/test_schema.db *test_schema.db .idea /Pipfile* +/.pytest_cache/ +/pip-wheel-metadata/ +/.vscode/ +/.ipynb_checkpoints/ diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 7d857d4feb..83f3c8d310 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -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): diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index aa56d0b6b3..6650125663 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -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"