{"record":{"id":"8e919b34beb7bc66","repo":"apache/beam","slug":"only-one-of-read-artifact-location-or-write-artifact","errorCode":null,"errorMessage":"Only one of read_artifact_location or write_artifact_location can be specified to initialize MLTransform","messagePattern":"Only one of read_artifact_location or write_artifact_location can be specified to initialize MLTransform","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/base.py","lineNumber":355,"sourceCode":"        overwrite any artifacts already in this location, so distinct locations\n        should be used for each instance of MLTransform. Only one of\n        write_artifact_location and read_artifact_location should be specified.\n      read_artifact_location: A storage location to read artifacts resulting\n        froma previous MLTransform. These artifacts include transformations\n        applied to the dataset and generated values like min, max from\n        ScaleTo01, and mean, var from ScaleToZScore. Note that when consuming\n        artifacts, it is not necessary to pass the transforms since they are\n        inherently stored within the artifacts themselves. The value assigned\n        to `read_artifact_location` should be a valid storage path where the\n        artifacts can be read from. Only one of write_artifact_location and\n        read_artifact_location should be specified.\n      transforms: A list of transforms to apply to the data. All the transforms\n        are applied in the order they are specified. The input of the\n        i-th transform is the output of the (i-1)-th transform. Multi-input\n        transforms are not supported yet.\n    \"\"\"\n    if read_artifact_location and write_artifact_location:\n      raise ValueError(\n          'Only one of read_artifact_location or write_artifact_location can '\n          'be specified to initialize MLTransform')\n\n    if not read_artifact_location and not write_artifact_location:\n      raise ValueError(\n          'Either a read_artifact_location or write_artifact_location must be '\n          'specified to initialize MLTransform')\n\n    if read_artifact_location:\n      artifact_location = read_artifact_location\n      artifact_mode = ArtifactMode.CONSUME\n      if transforms:\n        raise ValueError(\n            'Transforms should not be passed in read mode. In read mode, '\n            'the transforms are read from the artifact location.')\n\n    else:\n      artifact_location = write_artifact_location  # type: ignore[assignment]","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/base.py#L337-L373","documentation":"MLTransform is initialized in either produce (write artifacts) or consume (read artifacts) mode, never both. Passing both read_artifact_location and write_artifact_location is ambiguous, so a ValueError is raised.","triggerScenarios":"Calling MLTransform(read_artifact_location=..., write_artifact_location=...) with both locations set.","commonSituations":"Refactoring a write-mode pipeline to read-mode and leaving the old write_artifact_location argument in place; copy-pasting between training and inference pipeline examples.","solutions":["Keep only one of the two: write_artifact_location to produce artifacts, read_artifact_location to consume them.","If chaining transforms that both write and read, split into separate MLTransform steps in the pipeline."],"exampleFix":"// before\nMLTransform(read_artifact_location=read_dir, write_artifact_location=write_dir, transforms=[...])\n// after\nMLTransform(write_artifact_location=write_dir, transforms=[...])","handlingStrategy":"validation","validationCode":"def make_mltransform(**kw):\n    if kw.get('read_artifact_location') and kw.get('write_artifact_location'):\n        raise ValueError('Pass only one artifact location')\n    return MLTransform(**kw)","typeGuard":"def artifact_mode_ok(read_loc, write_loc) -> bool:\n    return bool(read_loc) != bool(write_loc)","tryCatchPattern":"try:\n    t = MLTransform(read_artifact_location=r, write_artifact_location=w, transforms=ts)\nexcept ValueError as e:\n    if 'Only one of' in str(e):\n        t = MLTransform(write_artifact_location=w, transforms=ts)\n    else:\n        raise","preventionTips":["Use a single mode flag (produce/consume) that selects exactly one artifact location","Never template both location kwargs into generated pipelines","Grep pipelines for both kwargs co-occurring in one MLTransform call"],"tags":["python","apache-beam","configuration"],"backgroundTag":"mutually-exclusive-options","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"}