diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-21 22:35:41 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-21 22:36:27 -0400 |
commit | e1f316fe7f51671c1eca8ebfacf4267b2bb0a44c (patch) | |
tree | 8224d3786d0cad9513dfb3758286d505526f36b7 /lib/sqlalchemy/sql/crud.py | |
parent | d09065d43d9914a1db45b89bd845072d7970155f (diff) | |
download | sqlalchemy-e1f316fe7f51671c1eca8ebfacf4267b2bb0a44c.tar.gz |
coerce for multivalues keys
Fixed issue where using ORM column expressions as keys in the list of
dictionaries passed to :meth:`_sql.Insert.values` for "multi-valued insert"
would not be processed correctly into the correct column expressions.
Fixes: #7060
Change-Id: I1c4c286c33ea6eeaafba617996828f5c88ff0a1c
Diffstat (limited to 'lib/sqlalchemy/sql/crud.py')
-rw-r--r-- | lib/sqlalchemy/sql/crud.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py index d43f33ebb..a9c9cb4c1 100644 --- a/lib/sqlalchemy/sql/crud.py +++ b/lib/sqlalchemy/sql/crud.py @@ -119,7 +119,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw): # special logic that only occurs for multi-table UPDATE # statements if compile_state.isupdate and compile_state.is_multitable: - _get_multitable_params( + _get_update_multitable_params( compiler, stmt, compile_state, @@ -172,7 +172,12 @@ def _get_crud_params(compiler, stmt, compile_state, **kw): if compile_state._has_multi_parameters: values = _extend_values_for_multiparams( - compiler, stmt, compile_state, values, kw + compiler, + stmt, + compile_state, + values, + _column_as_key, + kw, ) elif ( not values @@ -842,7 +847,7 @@ def _process_multiparam_default_bind(compiler, stmt, c, index, kw): return _create_update_prefetch_bind_param(compiler, col, **kw) -def _get_multitable_params( +def _get_update_multitable_params( compiler, stmt, compile_state, @@ -918,15 +923,25 @@ def _get_multitable_params( compiler.postfetch.append(c) -def _extend_values_for_multiparams(compiler, stmt, compile_state, values, kw): +def _extend_values_for_multiparams( + compiler, + stmt, + compile_state, + values, + _column_as_key, + kw, +): values_0 = values values = [values] for i, row in enumerate(compile_state._multi_parameters[1:]): extension = [] + + row = {_column_as_key(key): v for key, v in row.items()} + for (col, col_expr, param) in values_0: - if col in row or col.key in row: - key = col if col in row else col.key + if col.key in row: + key = col.key if coercions._is_literal(row[key]): new_param = _create_bind_param( |