summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-05-05 09:16:10 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2023-05-05 09:20:58 -0400
commitdc60e7a7d35a470c09ce590f37e949ff8e8cdcde (patch)
tree1b4a8eb5701ea62575fc975aa0a1700c553fb03a /lib
parentdb9a2caa43f0e8539bd1b3d8a2522f8018903605 (diff)
downloadsqlalchemy-dc60e7a7d35a470c09ce590f37e949ff8e8cdcde.tar.gz
add explicit step to set populate_existing for bulk insert
Fixed issue in new :ref:`orm_queryguide_upsert_returning` feature where the ``populate_existing`` execution option was not being propagated to the loading option, preventing existing attributes from being refreshed in-place. Fixes: #9746 Change-Id: I3efcab644e2b5874c6b265d5313f353c051db629
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/orm/bulk_persistence.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/bulk_persistence.py b/lib/sqlalchemy/orm/bulk_persistence.py
index cb416d69e..257d71db4 100644
--- a/lib/sqlalchemy/orm/bulk_persistence.py
+++ b/lib/sqlalchemy/orm/bulk_persistence.py
@@ -586,6 +586,7 @@ class ORMDMLState(AbstractORMCompileState):
load_options = execution_options.get(
"_sa_orm_load_options", QueryContext.default_load_options
)
+
querycontext = QueryContext(
compile_state.from_statement_ctx,
compile_state.select_statement,
@@ -1140,6 +1141,7 @@ class BulkORMInsert(ORMDMLState, InsertDMLState):
_return_defaults: bool = False
_subject_mapper: Optional[Mapper[Any]] = None
_autoflush: bool = True
+ _populate_existing: bool = False
select_statement: Optional[FromStatement] = None
@@ -1159,7 +1161,7 @@ class BulkORMInsert(ORMDMLState, InsertDMLState):
execution_options,
) = BulkORMInsert.default_insert_options.from_execution_options(
"_sa_orm_insert_options",
- {"dml_strategy", "autoflush"},
+ {"dml_strategy", "autoflush", "populate_existing"},
execution_options,
statement._execution_options,
)
@@ -1284,6 +1286,15 @@ class BulkORMInsert(ORMDMLState, InsertDMLState):
if not bool(statement._returning):
return result
+ if insert_options._populate_existing:
+ load_options = execution_options.get(
+ "_sa_orm_load_options", QueryContext.default_load_options
+ )
+ load_options += {"_populate_existing": True}
+ execution_options = execution_options.union(
+ {"_sa_orm_load_options": load_options}
+ )
+
return cls._return_orm_returning(
session,
statement,