@@ -374,7 +374,23 @@ def _import_structure(
374374 context = migration_context ,
375375 source_node = root_node ,
376376 )
377- change_log .save ()
377+ # Publishing is not allowed inside bulk_draft_changes_for(), so publish
378+ # everything that was modified now that the context has exited. We use the
379+ # change log to identify which drafts to publish. If the context produced
380+ # no records, it deletes the change log on exit (clearing its PK), in which
381+ # case there's nothing to publish and we return None so callers don't try
382+ # to associate the deleted change log with the migration.
383+ if not change_log .pk :
384+ return None , root_migrated_node
385+ if change_log .records .exists ():
386+ drafts_to_publish = content_api .get_all_drafts (migration .target .id ).filter (
387+ entity_id__in = change_log .records .values_list ("entity_id" , flat = True ),
388+ )
389+ content_api .publish_from_drafts (
390+ migration .target .id ,
391+ draft_qset = drafts_to_publish ,
392+ published_by = migration_context .created_by ,
393+ )
378394 return change_log , root_migrated_node
379395
380396
@@ -894,11 +910,7 @@ def _migrate_container(
894910 created_by = context .created_by ,
895911 ).publishable_entity_version
896912
897- # Publish the container
898- libraries_api .publish_container_changes (
899- container .container_key ,
900- context .created_by ,
901- )
913+ # Note: Publishing happens after bulk_draft_changes_for exits, in _import_structure.
902914 context .used_container_slugs .add (container .container_key .container_id )
903915 return container_publishable_entity_version , None
904916
@@ -972,8 +984,7 @@ def _migrate_component(
972984 target_key , new_olx_str = olx , paths_to_media = paths_to_media_ids ,
973985 )
974986
975- # Publish the component
976- libraries_api .publish_component_changes (target_key , context .created_by )
987+ # Note: Publishing happens after bulk_draft_changes_for exits, in _import_structure.
977988 context .used_component_keys .add (target_key )
978989 return component_version .publishable_entity_version , None
979990
0 commit comments