@@ -154,7 +154,7 @@ def get_existing_target(self, source_key: UsageKey) -> PublishableEntity:
154154 # NOTE: This is a list of PublishableEntities, but we always return the first one.
155155 return self .existing_source_to_target_keys [source_key ][0 ]
156156
157- def add_migration (self , source_key : UsageKey , target : PublishableEntity ) -> None :
157+ def add_migration (self , source_key : UsageKey , target : PublishableEntity | None ) -> None :
158158 """Update the context with a new migration (keeps it current)"""
159159 if source_key not in self .existing_source_to_target_keys :
160160 self .existing_source_to_target_keys [source_key ] = [target ]
@@ -166,7 +166,7 @@ def get_existing_target_entity_keys(self, base_key: str) -> set[str]:
166166 publishable_entity .key
167167 for publishable_entity_list in self .existing_source_to_target_keys .values ()
168168 for publishable_entity in publishable_entity_list
169- if publishable_entity .key .startswith (base_key )
169+ if publishable_entity and publishable_entity .key .startswith (base_key )
170170 )
171171
172172 @property
@@ -934,10 +934,10 @@ class _MigratedNode:
934934 This happens, particularly, if the node is above the requested composition level
935935 but has descendents which are at or below that level.
936936 """
937- source_to_target : tuple [UsageKey , PublishableEntityVersion ] | None
937+ source_to_target : tuple [UsageKey , PublishableEntityVersion | None ] | None
938938 children : list [_MigratedNode ]
939939
940- def all_source_to_target_pairs (self ) -> t .Iterable [tuple [UsageKey , PublishableEntityVersion ]]:
940+ def all_source_to_target_pairs (self ) -> t .Iterable [tuple [UsageKey , PublishableEntityVersion | None ]]:
941941 """
942942 Get all source_key->target_ver pairs via a pre-order traversal.
943943 """
@@ -1010,7 +1010,7 @@ def _migrate_node(
10101010 children = [
10111011 migrated_child .source_to_target [1 ]
10121012 for migrated_child in migrated_children if
1013- migrated_child .source_to_target
1013+ migrated_child .source_to_target and migrated_child . source_to_target [ 1 ]
10141014 ],
10151015 )
10161016 if container_type else
@@ -1021,9 +1021,8 @@ def _migrate_node(
10211021 title = title ,
10221022 )
10231023 )
1024- if target_entity_version :
1025- source_to_target = (source_key , target_entity_version )
1026- context .add_migration (source_key , target_entity_version .entity )
1024+ source_to_target = (source_key , target_entity_version )
1025+ context .add_migration (source_key , target_entity_version .entity if target_entity_version else None )
10271026 else :
10281027 log .warning (
10291028 f"Cannot migrate node from { context .source_context_key } to { context .target_library_key } "
@@ -1334,7 +1333,7 @@ def _create_migration_artifacts_incrementally(
13341333 ModulestoreBlockMigration .objects .create (
13351334 overall_migration = migration ,
13361335 source = block_source ,
1337- target_id = target_version .entity_id ,
1336+ target_id = target_version .entity_id if target_version else None ,
13381337 )
13391338
13401339 processed += 1
0 commit comments