code: def static_dataset_artifact(static_model_artifact, sagemaker_session):
      model_artifact_arn = static_model_artifact.artifact_arn
      dataset_associations = (
          sagemaker_session.sagemaker_client.list_associations(
              DestinationArn=model_artifact_arn, SourceType="DataSet"
          )
      )
      logging.info(
          f"Found {len(dataset_associations)} associated with model artifact {model_artifact_arn}"
      )
      if len(dataset_associations["AssociationSummaries"]) == 0:
          # no directly associated dataset. work backwards from the model
          model_associations = (
              sagemaker_session.sagemaker_client.list_associations(
                  DestinationArn=model_artifact_arn, SourceType="Model"
              )["AssociationSummaries"]
          )
  
          if len(model_associations) == 0:
              raise Exception(
                  f"No models associated with model artifact {model_artifact_arn}"
              )
  
          training_job_associations = (
              sagemaker_session.sagemaker_client.list_associations(
                  DestinationArn=model_associations[0]["SourceArn"],
                  SourceType="SageMakerTrainingJob",
              )["AssociationSummaries"]
          )
  
          if len(training_job_associations) == 0:
              raise Exception(
                  f"No training jobs associated with models for model artifact {model_artifact_arn}"
              )
  
          dataset_associations = (
              sagemaker_session.sagemaker_client.list_associations(
                  DestinationArn=training_job_associations[0][
                      "SourceArn"
                  ],
                  SourceType="DataSet",
              )
          )
  
      yield artifact.DatasetArtifact.load(
          dataset_associations["AssociationSummaries"][0]["SourceArn"],
          sagemaker_session=sagemaker_session,
      )
  
imports: from __future__ import absolute_import
  import time
  import boto3
  import pytest
  import logging
  import uuid
  import json
  from sagemaker.lineage import action, context, association, artifact
  from sagemaker.model import ModelPackage
  from sagemaker.utils import retry_with_backoff
  from tests.integ.sagemaker.workflow.test_workflow import test_end_to_end_pipeline_successful_execution
  from sagemaker.workflow.pipeline import _PipelineExecution
  from sagemaker.session import get_execution_role
  from smexperiments import trial_component, trial, experiment
  from random import randint
  from botocore.exceptions import ClientError
  from sagemaker.lineage.query import LineageQuery, LineageFilter, LineageSourceEnum, LineageEntityEnum, LineageQueryDirectionEnum
  from sagemaker.lineage.lineage_trial_component import LineageTrialComponent
  from tests.integ.sagemaker.lineage.helpers import name, names
label_desc: Use image node_id 36 for calling a global function with example usage: static_dataset_artifact(static_model_artifact, sagemaker_session) without return types