From e636917a721f4bb01264a23736c9c81e462863cb Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 10 Jan 2023 09:51:23 -0500 Subject: 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 --- lib/sqlalchemy/sql/crud.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql/crud.py') 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 = { -- cgit v1.2.1