summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-02-10 08:39:21 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-02-10 10:42:11 -0500
commiteb0861e8e69f8ce702301c558e552e1aeb2e9eba (patch)
tree638c8a08641e524b3ed54ee824275e5eb520ecbe /lib/sqlalchemy/sql/util.py
parent48aad8b244737ad7d2000056ce7320d6b32fa2de (diff)
downloadsqlalchemy-eb0861e8e69f8ce702301c558e552e1aeb2e9eba.tar.gz
generalize adapt_on_names to expect non-named elements
The fix in #9217 opened up adapt_on_names to more kinds of expressions than it was prepared for; adjust that logic and also refine in the ORM where we are using it, as we dont need it (yet) for the DML RETURNING use case. Fixed regression introduced in version 2.0.2 due to :ticket:`9217` where using DML RETURNING statements, as well as :meth:`_sql.Select.from_statement` constructs as was "fixed" in :ticket:`9217`, in conjunction with ORM mapped classes that used expressions such as with :func:`_orm.column_property`, would lead to an internal error within Core where it would attempt to match the expression by name. The fix repairs the Core issue, and also adjusts the fix in :ticket:`9217` to not take effect for the DML RETURNING use case, where it adds unnecessary overhead. Fixes: #9273 Change-Id: Ie0344efb12ff7df48f21e71e62dc598c76a6a0de
Diffstat (limited to 'lib/sqlalchemy/sql/util.py')
-rw-r--r--lib/sqlalchemy/sql/util.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index 1dad9ce68..0a50197a0 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -54,6 +54,7 @@ from .elements import ColumnElement
from .elements import Grouping
from .elements import KeyedColumnElement
from .elements import Label
+from .elements import NamedColumn
from .elements import Null
from .elements import UnaryExpression
from .schema import Column
@@ -712,7 +713,6 @@ class _repr_params(_repr_base):
return "(%s)" % elements
def _get_batches(self, params: Iterable[Any]) -> Any:
-
lparams = list(params)
lenparams = len(lparams)
if lenparams > self.max_params:
@@ -1122,7 +1122,6 @@ class ClauseAdapter(visitors.ReplacingExternalTraversal):
def _corresponding_column(
self, col, require_embedded, _seen=util.EMPTY_SET
):
-
newcol = self.selectable.corresponding_column(
col, require_embedded=require_embedded
)
@@ -1135,7 +1134,12 @@ class ClauseAdapter(visitors.ReplacingExternalTraversal):
)
if newcol is not None:
return newcol
- if self.adapt_on_names and newcol is None:
+
+ if (
+ self.adapt_on_names
+ and newcol is None
+ and isinstance(col, NamedColumn)
+ ):
newcol = self.selectable.exported_columns.get(col.name)
return newcol