class_docstr: Custom driver for model validator.
docstr: Fetch last blessed model in metadata based on span.
docstr_tok: ["Fetch","last","blessed","model","in","metadata","based","on","span","."]
code: def _fetch_last_blessed_model(
      self,
      pipeline_name: str,
      component_id: str,
  ) -> Tuple[Optional[str], Optional[int]]:
      """Fetch last blessed model in metadata based on span."""
      previous_blessed_models = []
      for a in self._metadata_handle.get_artifacts_by_type(
          "ModelBlessing"
      ):
          # TODO(ccy): get pipeline name from MLMD context.
          if "pipeline_name" in a.properties:
              p = a.properties["pipeline_name"].string_value
          else:
              p = a.custom_properties["pipeline_name"].string_value
          if (
              p == pipeline_name
              and a.custom_properties["blessed"].int_value == 1
              and a.custom_properties["component_id"].string_value
              == component_id
          ):
              previous_blessed_models.append(a)
  
      if previous_blessed_models:
          # TODO(b/138845899): consider use span instead of id.
          last_blessed_model = max(
              previous_blessed_models, key=lambda artifact: artifact.id
          )
          return (
              last_blessed_model.custom_properties[
                  "current_model"
              ].string_value,
              last_blessed_model.custom_properties[
                  "current_model_id"
              ].int_value,
          )
      else:
          return None, None
  
file_path: tfx/tfx/components/model_validator/driver.py
imports: from typing import Any, Dict, Optional, Tuple
  import absl
  from tfx.dsl.components.base import base_driver
  from tfx.orchestration import data_types
label_desc: Use image node_id 1 for calling the Driver obj's underlying member method code with example usage: obj._fetch_last_blessed_model(pipeline_name, component_id) and returns: last_blessed_model,  last_blessed_model, None,  None