From 77a17797ecc08736ea942e29f79df4f96bd74e0c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 3 Nov 2021 21:26:44 -0400 Subject: use ExpressionElementRole for case targets in case() Fixed regression where the :func:`_sql.text` construct would no longer be accepted as a target case in the "whens" list within a :func:`_sql.case` construct. The regression appears related to an attempt to guard against some forms of literal values that were considered to be ambiguous when passed here; however, there's no reason the target cases shouldn't be interpreted as open-ended SQL expressions just like anywhere else, and a literal string or tuple will be converted to a bound parameter as would be the case elsewhere. Fixes: #7287 Change-Id: I75478adfa115f3292cb1362cc5b2fdf152b0ed6f --- lib/sqlalchemy/sql/elements.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index f1fe46fd2..c8faebbd9 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -2943,28 +2943,18 @@ class Case(ColumnElement): pass value = kw.pop("value", None) - if value is not None: - whenlist = [ - ( - coercions.expect( - roles.ExpressionElementRole, - c, - apply_propagate_attrs=self, - ).self_group(), - coercions.expect(roles.ExpressionElementRole, r), - ) - for (c, r) in whens - ] - else: - whenlist = [ - ( - coercions.expect( - roles.ColumnArgumentRole, c, apply_propagate_attrs=self - ).self_group(), - coercions.expect(roles.ExpressionElementRole, r), - ) - for (c, r) in whens - ] + + whenlist = [ + ( + coercions.expect( + roles.ExpressionElementRole, + c, + apply_propagate_attrs=self, + ).self_group(), + coercions.expect(roles.ExpressionElementRole, r), + ) + for (c, r) in whens + ] if whenlist: type_ = list(whenlist[-1])[-1].type -- cgit v1.2.1