{"record":{"id":"3320fdc2c17808b0","repo":"apache/beam","slug":"artifact-mode-must-be-either-produce-or-consume","errorCode":null,"errorMessage":"artifact_mode must be either `produce` or `consume`.","messagePattern":"artifact_mode must be either `produce` or `consume`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/handlers.py","lineNumber":169,"sourceCode":"\nclass TFTProcessHandler(ProcessHandler[tft_process_handler_input_type,\n                                       tft_process_handler_output_type]):\n  def __init__(\n      self,\n      *,\n      artifact_location: str,\n      transforms: Optional[Sequence[TFTOperation]] = None,\n      artifact_mode: str = ArtifactMode.PRODUCE):\n    \"\"\"\n    A handler class for processing data with TensorFlow Transform (TFT)\n    operations.\n    \"\"\"\n    self.transforms = transforms if transforms else []\n    self.transformed_schema: dict[str, type] = {}\n    self.artifact_location = artifact_location\n    self.artifact_mode = artifact_mode\n    if artifact_mode not in ['produce', 'consume']:\n      raise ValueError('artifact_mode must be either `produce` or `consume`.')\n\n  def append_transform(self, transform):\n    self.transforms.append(transform)\n\n  def _map_column_names_to_types(self, row_type):\n    \"\"\"\n    Return a dictionary of column names and types.\n    Args:\n      element_type: A type of the element. This could be a NamedTuple or a Row.\n    Returns:\n      A dictionary of column names and types.\n    \"\"\"\n    try:\n      if not isinstance(row_type, RowTypeConstraint):\n        row_type = RowTypeConstraint.from_user_type(row_type)\n\n      inferred_types = {name: typ for name, typ in row_type._fields}\n","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/handlers.py#L151-L187","documentation":"MLTransform validates artifact_mode at construction: it controls whether the transform writes ('produce') or reads ('consume') artifacts like saved model weights and transforms metadata. Any value other than the two allowed strings raises ValueError.","triggerScenarios":"MLTransform(artifact_location=..., artifact_mode='write') or 'PRODUCE' or any misspelled value — only the exact strings 'produce' and 'consume' pass.","commonSituations":"Uppercasing the mode for style consistency; using verbs like 'read'/'write' from another framework's API.","solutions":["Use artifact_mode='produce' when the pipeline generates artifacts.","Use artifact_mode='consume' when applying saved artifacts.","Fix casing/typos — the check is case-sensitive."],"exampleFix":"// before\nMLTransform(artifact_location=uri, artifact_mode='write')\n// after\nMLTransform(artifact_location=uri, artifact_mode='produce')","handlingStrategy":"validation","validationCode":"assert artifact_mode in ('produce', 'consume'), f\"got {artifact_mode!r}\"","typeGuard":null,"tryCatchPattern":"try:\n    t = MLTransform(artifact_location=uri, artifact_mode=mode)\nexcept ValueError as e:\n    if 'artifact_mode' in str(e):\n        t = MLTransform(artifact_location=uri, artifact_mode='produce')","preventionTips":["Use a constant or Literal type for artifact_mode","Values are lowercase and case-sensitive"],"tags":["python","mltransform","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}