{"record":{"id":"10594580b615205b","repo":"apache/beam","slug":"the-artifact-location-s-already-exists-and-contains-s-please","errorCode":null,"errorMessage":"The artifact location %s already exists and contains %s. Please specify a different location.","messagePattern":"The artifact location (.+?) already exists and contains (.+?)\\. Please specify a different location\\.","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/transforms/base.py","lineNumber":554,"sourceCode":"    if not is_gcs and path.find('://') != -1:\n      raise RuntimeError(\n          \"Artifact locations are currently supported for only available for \"\n          \"local paths and GCS paths. Got: %s\" % path)\n    return is_gcs\n\n  @staticmethod\n  def save_attributes(\n      ptransform_list,\n      artifact_location,\n      **kwargs,\n  ):\n    # if an artifact location is present, instead of overwriting the\n    # existing file, raise an error since the same artifact location\n    # can be used by multiple beam jobs and this could result in undesired\n    # behavior.\n    if FileSystems.exists(FileSystems.join(artifact_location,\n                                           _ATTRIBUTE_FILE_NAME)):\n      raise FileExistsError(\n          \"The artifact location %s already exists and contains %s. Please \"\n          \"specify a different location.\" %\n          (artifact_location, _ATTRIBUTE_FILE_NAME))\n\n    if _JsonPickleTransformAttributeManager._is_remote_path(artifact_location):\n      temp_dir = tempfile.mkdtemp()\n      temp_json_file = os.path.join(temp_dir, _ATTRIBUTE_FILE_NAME)\n      with open(temp_json_file, 'w+') as f:\n        f.write(jsonpickle.encode(ptransform_list))\n      with open(temp_json_file, 'rb') as f:\n        from apache_beam.runners.dataflow.internal import apiclient\n        _LOGGER.info('Creating artifact location: %s', artifact_location)\n        # pipeline options required to for the client to configure project.\n        options = kwargs.get('options')\n        try:\n          apiclient.DataflowApplicationClient(options=options).stage_file(\n              gcs_or_local_path=artifact_location,\n              file_name=_ATTRIBUTE_FILE_NAME,","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/transforms/base.py#L536-L572","documentation":"To avoid corrupting artifacts shared across Beam jobs, the JsonPickle attribute manager refuses to overwrite an existing attributes file. Before saving it checks FileSystems.exists(artifact_location/<attribute file>) and raises FileExistsError if the artifact file is already present.","triggerScenarios":"Re-running MLTransform with the same artifact_location that a previous run already populated; pointing two pipelines at the same artifact directory.","commonSituations":"Iterating on a pipeline without bumping/changing artifact_location; a failed run left a partial artifact directory behind; scheduled jobs reusing a fixed artifact path.","solutions":["Choose a new, unique artifact_location (e.g. include a run id/uuid) for this run.","Manually delete the existing artifact directory (or just the attribute file) if the old artifacts are no longer needed.","In CI/production, generate the artifact path per-run: artifact_location=os.path.join(base, uuid.uuid4().hex)."],"exampleFix":"// before\nMLTransform(artifact_location='gs://bucket/artifacts')\n// after\nMLTransform(artifact_location=f'gs://bucket/artifacts/{uuid.uuid4().hex[:6]}')","handlingStrategy":"validation","validationCode":"from apache_beam.io.filesystems import FileSystems\nimport os\nif FileSystems.exists(FileSystems.join(artifact_location, 'attributes.json')):\n    artifact_location = os.path.join(artifact_location, uuid.uuid4().hex[:6])","typeGuard":null,"tryCatchPattern":"try:\n    save_attributes(artifact_location)\nexcept FileExistsError:\n    artifact_location = os.path.join(artifact_location, uuid.uuid4().hex[:6])\n    save_attributes(artifact_location)","preventionTips":["Generate a unique artifact_location per run (uuid suffix).","Never reuse artifact directories across pipeline versions.","Clean up stale artifact dirs in CI before runs."],"tags":["python","file-exists","artifact-location"],"backgroundTag":"file-already-exists","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"}