{"record":{"id":"70a50b2ed9d16102","repo":"apache/beam","slug":"unable-to-copy-unequal-number-of-sources-and-destinations-70a50b","errorCode":null,"errorMessage":"Unable to copy unequal number of sources and destinations.","messagePattern":"Unable to copy unequal number of sources and destinations\\.","errorType":"validation","errorClass":"BeamIOError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/azure/blobstoragefilesystem.py","lineNumber":194,"sourceCode":"      compression_type: Type of compression to be used for this object\n\n    Returns: file handle with a close function for the user to use\n    \"\"\"\n    return self._path_open(path, 'rb', mime_type, compression_type)\n\n  def copy(self, source_file_names, destination_file_names):\n    \"\"\"Recursively copy the file tree from the source to the destination\n\n    Args:\n      source_file_names: list of source file objects that needs to be copied\n      destination_file_names: list of destination of the new object\n\n    Raises:\n      ``BeamIOError``: if any of the copy operations fail\n    \"\"\"\n    if not len(source_file_names) == len(destination_file_names):\n      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))","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/azure/blobstoragefilesystem.py#L176-L212","documentation":"BlobStorageFileSystem.copy requires source_file_names and destination_file_names to be the same length; otherwise it raises BeamIOError before touching storage. Batch copy/rename operations are defined pairwise, so mismatched lists are a caller bug.","triggerScenarios":"Calling copy(srcs, dests) where len(srcs) != len(dests), e.g. building destinations with a filter applied to sources, or renaming a subset of matched files without trimming the destination list.","commonSituations":"Generating destination names in a loop that skips duplicates while sources are unfiltered; concatenating lists on one side only; off-by-one when appending destinations conditionally.","solutions":["Assert len(source_file_names) == len(destination_file_names) before calling copy/rename.","Filter both lists together (zip then unzip) so they stay aligned.","Compute destinations via a transformation applied to sources instead of building them independently."],"exampleFix":"// before\nfsys.copy(sources, [rename(s) for s in sources if skip(s) == False])  # length mismatch\n// after\npairs = [(s, rename(s)) for s in sources if not skip(s)]\nsrcs, dests = zip(*pairs)\nfsys.copy(list(srcs), list(dests))","handlingStrategy":"validation","validationCode":"if len(source_file_names) != len(destination_file_names):\n    raise ValueError('sources and destinations must be equal length')","typeGuard":"def is_balanced_pair(srcs, dests):\n    return len(srcs) == len(dests)","tryCatchPattern":"try:\n    fsys.copy(srcs, dests)\nexcept BeamIOError as e:\n    logging.error(\"copy failed: %s\", e)\n    raise","preventionTips":["Build src/dest lists together (zip-transform-unzip) so they can't diverge.","Assert equal lengths in tests for rename/copy helpers.","Avoid conditionally appending to only one of the two lists."],"tags":["python","azure","blob-storage","argument-mismatch"],"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-20T03:17:13.778Z"}