{"record":{"id":"01b51773e640f759","repo":"apache/beam","slug":"cannot-create-object-with-unspecified-or-no-compression","errorCode":null,"errorMessage":"Cannot create object with unspecified or no compression","messagePattern":"Cannot create object with unspecified or no compression","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/filesystem.py","lineNumber":158,"sourceCode":"  # The bit mask to use for the wbits parameters of the zlib compressor and\n  # decompressor objects.\n  _gzip_mask = zlib.MAX_WBITS | 16  # Mask when using GZIP headers.\n\n  def __init__(\n      self,\n      fileobj: BinaryIO,\n      compression_type=CompressionTypes.GZIP,\n      read_size=DEFAULT_READ_BUFFER_SIZE):\n    if not fileobj:\n      raise ValueError('File object must not be None')\n\n    if not CompressionTypes.is_valid_compression_type(compression_type):\n      raise TypeError(\n          'compression_type must be CompressionType object but '\n          'was %s' % type(compression_type))\n    if compression_type in (CompressionTypes.AUTO,\n                            CompressionTypes.UNCOMPRESSED):\n      raise ValueError(\n          'Cannot create object with unspecified or no compression')\n\n    self._file = fileobj\n    self._compression_type = compression_type\n\n    if self._file.tell() != 0:\n      raise ValueError(\n          'File object must be at position 0 but was %d' % self._file.tell())\n    self._uncompressed_position = 0\n    self._uncompressed_size: Optional[int] = None\n\n    if self.readable():\n      self._read_size = read_size\n      self._read_buffer = io.BytesIO()\n      self._read_position = 0\n      self._read_eof = False\n\n      self._initialize_decompressor()","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/filesystem.py#L140-L176","documentation":"CompressedFile's whole purpose is to wrap a compressed stream; creating it with AUTO (deferred detection) or UNCOMPRESSED (no compression) leaves it with no codec, which is a contradictory request. The constructor raises ValueError for these sentinel values.","triggerScenarios":"filesystem.CompressedFile(fh, compression_type=CompressionTypes.AUTO) or CompressionTypes.UNCOMPRESSED.","commonSituations":"Propagating a compression_type read from FileMetadata (often AUTO) directly into CompressedFile; passing UNCOMPRESSED thinking it behaves like a plain file wrapper.","solutions":["Resolve AUTO to a concrete type first (e.g. via CompressionTypes.detect_compression_type(filename) or filesystems logic) before constructing CompressedFile.","For uncompressed data, use the raw file object directly instead of CompressedFile.","Route through FileSystems.open(), which resolves AUTO/UNCOMPRESSED appropriately."],"exampleFix":"# before\nCompressedFile(fh, compression_type=CompressionTypes.AUTO)\n# after\ntype_ = CompressionTypes.detect_compression_type(file_name)\nif type_ in (CompressionTypes.AUTO, CompressionTypes.UNCOMPRESSED):\n    reader = fh  # plain file\nelse:\n    reader = CompressedFile(fh, compression_type=type_)","handlingStrategy":"validation","validationCode":"if ctype in (CompressionTypes.AUTO, CompressionTypes.UNCOMPRESSED):\n    ctype = CompressionTypes.detect_compression_type(file_name)\nreader = CompressedFile(fh, compression_type=ctype) if ctype not in (CompressionTypes.AUTO, CompressionTypes.UNCOMPRESSED) else fh","typeGuard":"def is_concrete_compression(v) -> bool:\n    return v not in (CompressionTypes.AUTO, CompressionTypes.UNCOMPRESSED)","tryCatchPattern":null,"preventionTips":["Resolve AUTO compression at the filename level before constructing CompressedFile.","Prefer FileSystems.open(), which handles AUTO/UNCOMPRESSED transparently."],"tags":["python","apache-beam","io","invalid-enum-value"],"backgroundTag":"invalid-enum-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"}