summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/bulk_persistence.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/bulk_persistence.py')
-rw-r--r--lib/sqlalchemy/orm/bulk_persistence.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/bulk_persistence.py b/lib/sqlalchemy/orm/bulk_persistence.py
index 3ed34a57a..b407fcdca 100644
--- a/lib/sqlalchemy/orm/bulk_persistence.py
+++ b/lib/sqlalchemy/orm/bulk_persistence.py
@@ -591,6 +591,7 @@ class BulkUDCompileState(ORMDMLState):
"_sa_orm_update_options",
{
"synchronize_session",
+ "autoflush",
"is_delete_using",
"is_update_from",
"dml_strategy",
@@ -1079,6 +1080,7 @@ class BulkORMInsert(ORMDMLState, InsertDMLState):
_render_nulls: bool = False
_return_defaults: bool = False
_subject_mapper: Optional[Mapper[Any]] = None
+ _autoflush: bool = True
select_statement: Optional[FromStatement] = None
@@ -1098,7 +1100,7 @@ class BulkORMInsert(ORMDMLState, InsertDMLState):
execution_options,
) = BulkORMInsert.default_insert_options.from_execution_options(
"_sa_orm_insert_options",
- {"dml_strategy"},
+ {"dml_strategy", "autoflush"},
execution_options,
statement._execution_options,
)
@@ -1142,6 +1144,9 @@ class BulkORMInsert(ORMDMLState, InsertDMLState):
context._orm_load_exec_options
)
+ if insert_options._autoflush:
+ session._autoflush()
+
statement = statement._annotate(
{"dml_strategy": insert_options._dml_strategy}
)