summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-02-09 15:36:38 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-02-09 16:45:14 -0500
commit6971ba97247928c9a79f532001278d0e1d5845fc (patch)
tree2ab9961ca54035b675e355a5bb539f5dfb612a64 /lib/sqlalchemy/sql
parent13d3b2c291f49525bc38d082d1c2abe9e03bd3fe (diff)
downloadsqlalchemy-6971ba97247928c9a79f532001278d0e1d5845fc.tar.gz
apply self_group to all elements of multi-expression
Fixed critical regression in SQL expression formulation in the 2.0 series due to :ticket:`7744` which improved support for SQL expressions that contained many elements against the same operator repeatedly; parenthesis grouping would be lost with expression elements beyond the first two elements. Fixes: #9271 Change-Id: Ib6ed5b71efe0f6816dab75bda622297fc89e3b49
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/elements.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 37d53b30a..4c2c7de3c 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -547,7 +547,6 @@ class ClauseElement(
optionaldict: Optional[Mapping[str, Any]],
kwargs: Dict[str, Any],
) -> Self:
-
if optionaldict:
kwargs.update(optionaldict)
@@ -2780,7 +2779,6 @@ class OperatorExpression(ColumnElement[_T]):
negate: Optional[OperatorType] = None,
modifiers: Optional[Mapping[str, Any]] = None,
) -> OperatorExpression[_T]:
-
if operators.is_associative(op):
assert (
negate is None
@@ -2805,7 +2803,9 @@ class OperatorExpression(ColumnElement[_T]):
if multi:
return ExpressionClauseList._construct_for_list(
- op, type_, *(left_flattened + right_flattened)
+ op,
+ type_,
+ *(left_flattened + right_flattened),
)
return BinaryExpression(
@@ -2886,7 +2886,12 @@ class ExpressionClauseList(OperatorExpression[_T]):
) -> ExpressionClauseList[_T]:
self = cls.__new__(cls)
self.group = group
- self.clauses = clauses
+ if group:
+ self.clauses = tuple(
+ c.self_group(against=operator) for c in clauses
+ )
+ else:
+ self.clauses = clauses
self.operator = operator
self.type = type_
return self
@@ -2961,7 +2966,6 @@ class BooleanClauseList(ExpressionClauseList[bool]):
*clauses: Any,
**kw: Any,
) -> ColumnElement[Any]:
-
if initial_clause is _NoArg.NO_ARG:
# no elements period. deprecated use case. return an empty
# ClauseList construct that generates nothing unless it has
@@ -3233,7 +3237,6 @@ class Case(ColumnElement[_T]):
value: Optional[Any] = None,
else_: Optional[Any] = None,
):
-
new_whens: Iterable[Any] = coercions._expression_collection_was_a_list(
"whens", "case", whens
)
@@ -4908,7 +4911,6 @@ class CollationClause(ColumnElement[str]):
class _IdentifiedClause(Executable, ClauseElement):
-
__visit_name__ = "identified"
def __init__(self, ident):
@@ -5195,7 +5197,6 @@ class _anonymous_label(_truncated_label):
enclosing_label: Optional[str] = None,
sanitize_key: bool = False,
) -> _anonymous_label:
-
# need to escape chars that interfere with format
# strings in any case, issue #8724
body = re.sub(r"[%\(\) \$]+", "_", body)