summaryrefslogtreecommitdiff
path: root/test/sql/test_update.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-01-23 17:51:38 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-01-25 18:03:48 -0500
commit1de64504d8e68e2c0d14669c7638cf6f6d74973f (patch)
treebcb2f19fe89efc629408c4576c355f3fe998578b /test/sql/test_update.py
parent411637fbcf679f36448f1b094afef375158df15e (diff)
downloadsqlalchemy-1de64504d8e68e2c0d14669c7638cf6f6d74973f.tar.gz
Deprecate empty or_() and and_()
Creating an :func:`.and_` or :func:`.or_` construct with no arguments or empty ``*args`` will now emit a deprecation warning, as the SQL produced is a no-op (i.e. it renders as a blank string). This behavior is considered to be non-intuitive, so for empty or possibly empty :func:`.and_` or :func:`.or_` constructs, an appropriate default boolean should be included, such as ``and_(True, *args)`` or ``or_(False, *args)``. As has been the case for many major versions of SQLAlchemy, these particular boolean values will not render if the ``*args`` portion is non-empty. As there are some internal cases where an empty and_() construct is used in order to build an optional WHERE expression, a private utility function is added to suit this use case. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #5054 Closes: #5062 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5062 Pull-request-sha: 5ca2f27281977d74e390148c0fb8deaa0e0e4ad9 Change-Id: I599b9c8befa64d9a59a35ad7dd84ff400e3aa647
Diffstat (limited to 'test/sql/test_update.py')
-rw-r--r--test/sql/test_update.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/sql/test_update.py b/test/sql/test_update.py
index e625b7d9c..0313db832 100644
--- a/test/sql/test_update.py
+++ b/test/sql/test_update.py
@@ -1,4 +1,3 @@
-from sqlalchemy import and_
from sqlalchemy import bindparam
from sqlalchemy import column
from sqlalchemy import exc
@@ -8,7 +7,6 @@ from sqlalchemy import func
from sqlalchemy import Integer
from sqlalchemy import literal
from sqlalchemy import MetaData
-from sqlalchemy import or_
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import table
@@ -18,6 +16,8 @@ from sqlalchemy import update
from sqlalchemy import util
from sqlalchemy.dialects import mysql
from sqlalchemy.engine import default
+from sqlalchemy.sql import operators
+from sqlalchemy.sql.elements import BooleanClauseList
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import AssertsCompiledSQL
@@ -634,12 +634,16 @@ class UpdateTest(_UpdateFromTestBase, fixtures.TablesTest, AssertsCompiledSQL):
def test_where_empty(self):
table1 = self.tables.mytable
self.assert_compile(
- table1.update().where(and_()),
+ table1.update().where(
+ BooleanClauseList._construct_raw(operators.and_)
+ ),
"UPDATE mytable SET myid=:myid, name=:name, "
"description=:description",
)
self.assert_compile(
- table1.update().where(or_()),
+ table1.update().where(
+ BooleanClauseList._construct_raw(operators.or_)
+ ),
"UPDATE mytable SET myid=:myid, name=:name, "
"description=:description",
)