{"record":{"id":"14b43bd1af7c326e","repo":"apache/beam","slug":"unable-to-rename-unequal-number-of-sources-and-destinations-14b43b","errorCode":null,"errorMessage":"Unable to rename unequal number of sources and destinations.","messagePattern":"Unable to rename unequal number of sources and destinations\\.","errorType":"validation","errorClass":"BeamIOError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/azure/blobstoragefilesystem.py","lineNumber":211,"sourceCode":"      message = 'Unable to copy unequal number of sources and destinations.'\n      raise BeamIOError(message)\n    src_dest_pairs = list(zip(source_file_names, destination_file_names))\n    return self._blobstorageIO().copy_paths(src_dest_pairs)\n\n  def rename(self, source_file_names, destination_file_names):\n    \"\"\"Rename the files at the source list to the destination list.\n    Source and destination lists should be of the same size.\n\n    Args:\n      source_file_names: List of file paths that need to be moved\n      destination_file_names: List of destination_file_names for the files\n\n    Raises:\n      ``BeamIOError``: if any of the rename operations fail\n    \"\"\"\n    if not len(source_file_names) == len(destination_file_names):\n      message = 'Unable to rename unequal number of sources and destinations.'\n      raise BeamIOError(message)\n    src_dest_pairs = list(zip(source_file_names, destination_file_names))\n    results = self._blobstorageIO().rename_files(src_dest_pairs)\n    # Retrieve exceptions.\n    exceptions = {(src, dest): error\n                  for (src, dest, error) in results if error is not None}\n    if exceptions:\n      raise BeamIOError(\"Rename operation failed.\", exceptions)\n\n  def exists(self, path):\n    \"\"\"Check if the provided path exists on the FileSystem.\n\n    Args:\n      path: string path that needs to be checked.\n\n    Returns: boolean flag indicating if path exists\n    \"\"\"\n    try:\n      return self._blobstorageIO().exists(path)","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/azure/blobstoragefilesystem.py#L193-L229","documentation":"apache_beam.io.azure.blobstoragefilesystem.BlobStorageFileSystem.rename() raises BeamIOError with this message when the source_file_names and destination_file_names lists passed to it do not have the same number of elements. The bulk rename API works on (source, destination) pairs, so an unequal count would leave some sources unmapped or some destinations undefined; the check happens before any rename is attempted, so no files are moved.","triggerScenarios":"Calling rename(source_file_names, destination_file_names) where len(source_file_names) != len(destination_file_names), e.g. building the lists in separate loops where one silently drops items, or appending destinations only conditionally.","commonSituations":"Pipeline code that computes source file lists from a glob match but hand-writes or partially generates the destination list; a bug where a filtered-out source still has its destination appended (or vice versa); typos like passing the same list twice for a different operation.","solutions":["Verify len(source_file_names) == len(destination_file_names) before calling rename and fix the code that builds the shorter list","If you intended a one-to-one rename of one file, pass single-element lists, not a bare string wrapped inconsistently","Log both lists (or their lengths) at the point of call to find where they diverge","If sources were discovered dynamically, derive destinations from the same iteration so they stay paired"],"exampleFix":"// before\nfs.rename(sources, destinations)  # lengths differ\n// after\nassert len(sources) == len(destinations), f\"{len(sources)} sources vs {len(destinations)} destinations\"\nfs.rename(sources, destinations)","handlingStrategy":"validation","validationCode":"if len(source_file_names) != len(destination_file_names):\n    raise ValueError(\n        f\"rename: {len(source_file_names)} sources != {len(destination_file_names)} destinations\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build source and destination lists in the same loop/zip so they cannot diverge","Add an assert on equal lengths at the call site during development","Derive destinations from sources programmatically (e.g. prefix replacement) instead of hand-writing them","Write a unit test that feeds mismatched lists to catch list-building bugs"],"tags":["python","apache-beam","azure-blob-storage","argument-count-mismatch","filesystem-io"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}