From ed515f2ca16e1b40efe5ee0299417f8d6eb51b86 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 19 Mar 2021 10:34:31 -0400 Subject: Correct for coercion from list args to positional for case Fixed regression in the :func:`_sql.case` construct, where the "dictionary" form of argument specification failed to work correctly if it were passed positionally, rather than as a "whens" keyword argument. Fixes: #6097 Change-Id: I4138f54309a08c8e4e63cfafc211176e0b9a76c7 --- lib/sqlalchemy/sql/coercions.py | 2 +- lib/sqlalchemy/sql/elements.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py index 76ba7e214..35ac1a5ba 100644 --- a/lib/sqlalchemy/sql/coercions.py +++ b/lib/sqlalchemy/sql/coercions.py @@ -98,7 +98,7 @@ def _document_text_coercion(paramname, meth_rst, param_rst): def _expression_collection_was_a_list(attrname, fnname, args): - if args and isinstance(args[0], (list, set)) and len(args) == 1: + if args and isinstance(args[0], (list, set, dict)) and len(args) == 1: util.warn_deprecated_20( 'The "%s" argument to %s() is now passed as a series of ' "positional " diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 26c03b57b..b3b041385 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -2618,7 +2618,7 @@ class Case(ColumnElement): acts somewhat analogously to an "if/then" construct in other languages. It returns an instance of :class:`.Case`. - :func:`.case` in its usual form is passed a list of "when" + :func:`.case` in its usual form is passed a series of "when" constructs, that is, a list of conditions and results as tuples:: from sqlalchemy import case @@ -2653,7 +2653,7 @@ class Case(ColumnElement): stmt = select(users_table).\ where( case( - {"wendy": "W", "jack": "J"}, + whens={"wendy": "W", "jack": "J"}, value=users_table.c.name, else_='E' ) -- cgit v1.2.1