summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/crud.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-01-10 09:51:23 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-01-11 11:48:33 -0500
commit2d41f5d8c4de8074648d0fd10f213a44e94319ca (patch)
treef51acde7848e738788a796852e7d66e21fb52677 /lib/sqlalchemy/sql/crud.py
parent13a5e3ac1ca93e09535f026fc8b9ce36dfbeeb14 (diff)
downloadsqlalchemy-2d41f5d8c4de8074648d0fd10f213a44e94319ca.tar.gz
fix ORM support for column-named bindparam() in crud .values()
Fixed bug / regression where using :func:`.bindparam()` with the same name as a column in the :meth:`.Update.values` method of :class:`.Update`, as well as the :meth:`.Insert.values` method of :class:`.Insert` in 2.0 only, would in some cases silently fail to honor the SQL expression in which the parameter were presented, replacing the expression with a new parameter of the same name and discarding any other elements of the SQL expression, such as SQL functions, etc. The specific case would be statements that were constructed against ORM entities rather than plain :class:`.Table` instances, but would occur if the statement were invoked with a :class:`.Session` or a :class:`.Connection`. :class:`.Update` part of the issue was present in both 2.0 and 1.4 and is backported to 1.4. For 1.4, also backports the sqlalchemy.testing.Variation update to the variation() API. Fixes: #9075 Change-Id: Ie954bc1f492ec6a566163588182ef4910c7ee452 (cherry picked from commit b5b864e0fe50243a94c0ef04fddda6fa446c1524)
Diffstat (limited to 'lib/sqlalchemy/sql/crud.py')
-rw-r--r--lib/sqlalchemy/sql/crud.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py
index 48ab72128..4f509d9a5 100644
--- a/lib/sqlalchemy/sql/crud.py
+++ b/lib/sqlalchemy/sql/crud.py
@@ -77,14 +77,17 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
if compile_state._has_multi_parameters:
spd = compile_state._multi_parameters[0]
stmt_parameter_tuples = list(spd.items())
+ spd_str_key = {_column_as_key(key) for key in spd}
elif compile_state._ordered_values:
spd = compile_state._dict_parameters
stmt_parameter_tuples = compile_state._ordered_values
+ spd_str_key = {_column_as_key(key) for key in spd}
elif compile_state._dict_parameters:
spd = compile_state._dict_parameters
stmt_parameter_tuples = list(spd.items())
+ spd_str_key = {_column_as_key(key) for key in spd}
else:
- stmt_parameter_tuples = spd = None
+ stmt_parameter_tuples = spd = spd_str_key = None
# if we have statement parameters - set defaults in the
# compiled params
@@ -94,7 +97,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
parameters = dict(
(_column_as_key(key), REQUIRED)
for key in compiler.column_keys
- if key not in spd
+ if key not in spd_str_key
)
else:
parameters = dict(