Skip to content

Commit 059ac41

Browse files
committed
fix: handle missing pipeline version context in lineage update
_update_pipeline_lineage assumed the version context always exists. When it's been deleted or never created (e.g. prior run failure), DescribeContext throws ResourceNotFound. Now catches the error and recreates the version context with proper associations.
1 parent 37d081a commit 059ac41

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

‎sagemaker-mlops/src/sagemaker/mlops/feature_store/feature_processor/lineage/_feature_processor_lineage.py‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,39 @@ def _update_pipeline_lineage(
359359

360360
# If pipeline lineage exists then determine whether to create a new version.
361361
pipeline_context: Context = self._get_pipeline_context()
362-
current_pipeline_version_context: Context = self._get_pipeline_version_context(
363-
last_update_time=pipeline_context.properties[LAST_UPDATE_TIME]
364-
)
362+
try:
363+
current_pipeline_version_context: Context = self._get_pipeline_version_context(
364+
last_update_time=pipeline_context.properties[LAST_UPDATE_TIME]
365+
)
366+
except ClientError as e:
367+
if e.response[ERROR][CODE] == RESOURCE_NOT_FOUND:
368+
# Pipeline version context does not exist (possibly deleted or never created).
369+
# Create a new pipeline version context and its associations.
370+
logger.info(
371+
"Pipeline version context not found. Creating new pipeline version lineage."
372+
)
373+
pipeline_context.properties["LastUpdateTime"] = self.pipeline[
374+
LAST_MODIFIED_TIME
375+
].strftime("%s")
376+
PipelineLineageEntityHandler.update_pipeline_context(
377+
pipeline_context=pipeline_context
378+
)
379+
new_pipeline_version_context: Context = self._create_pipeline_version_lineage()
380+
self._add_associations_for_pipeline(
381+
pipeline_context_arn=pipeline_context.context_arn,
382+
pipeline_versions_context_arn=new_pipeline_version_context.context_arn,
383+
input_feature_group_contexts=input_feature_group_contexts,
384+
input_raw_data_artifacts=input_raw_data_artifacts,
385+
output_feature_group_contexts=output_feature_group_contexts,
386+
transformation_code_artifact=transformation_code_artifact,
387+
)
388+
LineageAssociationHandler.add_pipeline_and_pipeline_version_association(
389+
pipeline_context_arn=pipeline_context.context_arn,
390+
pipeline_version_context_arn=new_pipeline_version_context.context_arn,
391+
sagemaker_session=self.sagemaker_session,
392+
)
393+
return
394+
raise e
365395
upstream_feature_group_associations: Iterator[AssociationSummary] = (
366396
LineageAssociationHandler.list_upstream_associations(
367397
# pylint: disable=no-member

0 commit comments

Comments
 (0)