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:47:02 -0500
commite636917a721f4bb01264a23736c9c81e462863cb (patch)
treef039595c1eb6f06865ee9a67b77011b035dd2561 /lib/sqlalchemy/sql/crud.py
parenta950402dae2a5b2448f5f4235946b2f767c7485c (diff)
downloadsqlalchemy-e636917a721f4bb01264a23736c9c81e462863cb.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. Fixes: #9075 Change-Id: Ie954bc1f492ec6a566163588182ef4910c7ee452
Diffstat (limited to 'lib/sqlalchemy/sql/crud.py')
-rw-r--r--lib/sqlalchemy/sql/crud.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py
index ca215bd88..5017afa78 100644
--- a/lib/sqlalchemy/sql/crud.py
+++ b/lib/sqlalchemy/sql/crud.py
@@ -212,25 +212,29 @@ def _get_crud_params(
assert mp is not None
spd = mp[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
+ assert spd is not None
+ 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
if compiler.column_keys is None:
parameters = {}
elif stmt_parameter_tuples:
- assert spd is not None
+ assert spd_str_key is not None
parameters = {
_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 = {