{"record":{"id":"5c76b0f176e6ae00","repo":"apache/beam","slug":"delete-operation-failed-localfilesystem","errorCode":null,"errorMessage":"Delete operation failed","messagePattern":"Delete operation failed","errorType":"exception","errorClass":"BeamIOError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/localfilesystem.py","lineNumber":368,"sourceCode":"\n    def try_delete(path):\n      try:\n        _delete_path(path)\n      except Exception as e:  # pylint: disable=broad-except\n        exceptions[path] = e\n\n    for match_result in self.match(paths):\n      metadata_list = match_result.metadata_list\n\n      if not metadata_list:\n        exceptions[match_result.pattern] = \\\n          IOError('No files found to delete under: %s' % match_result.pattern)\n\n      for metadata in match_result.metadata_list:\n        try_delete(metadata.path)\n\n    if exceptions:\n      raise BeamIOError(\"Delete operation failed\", exceptions)\n\n  def report_lineage(self, path, lineage):\n    lineage.add('filesystem', 'localhost', path, last_segment_sep='/')\n","sourceCodeStart":350,"sourceCodeEnd":372,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/localfilesystem.py#L350-L372","documentation":"Filesystem.delete() collects per-path failures (each as BeamIOError) in an exceptions dict; if any path failed to delete it raises a single BeamIOError('Delete operation failed') whose exception_payload carries the per-path details. It also raises if no files matched the pattern ('No files found to delete under: ...').","triggerScenarios":"Passing a list of paths/globs to delete() where one or more paths cannot be removed (permissions, open file handles, vanished mid-run), or where the glob matches no files at all.","commonSituations":"Batch cleanup of Beam temp/staging files where a running job still holds files; glob patterns with a typo matching nothing; mixed-path batches where a subset of deletions fail.","solutions":["Inspect the exception_payload of the raised BeamIOError to find which specific paths failed, then fix those individually.","Verify the glob/path list matches existing files before deleting (use match() first).","Fix permissions or release file locks for the failing paths and retry.","Wrap delete() in try/except BeamIOError and treat per-path failures as non-fatal if cleanup is best-effort."],"exampleFix":"// before\nfs.delete(['gs-tmp-*'])\n// after\ntry:\n    fs.delete(['/tmp/output/*.tmp'])\nexcept BeamIOError as e:\n    for path, err in (e.exception_payload or {}).items():\n        print('failed to delete', path, err)","handlingStrategy":"try-catch","validationCode":"matches = fs.match([pattern])\nassert matches[0].metadata_list, 'nothing to delete'","typeGuard":null,"tryCatchPattern":"try:\n    fs.delete(paths)\nexcept BeamIOError as e:\n    failed = getattr(e, 'exception_payload', {})\n    # retry or skip only the failed paths","preventionTips":["Call match() first to verify the glob finds files.","Inspect exception_payload to identify failing paths.","Treat cleanup as best-effort with a per-path retry loop."],"tags":["filesystem","batch-delete","beam-io"],"backgroundTag":"file-write-failed","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"}