{"record":{"id":"c7b812fed1057ae5","repo":"apache/beam","slug":"compression-type-must-be-compressiontype-object-but-was-s-c7b812","errorCode":null,"errorMessage":"compression_type must be CompressionType object but was %s","messagePattern":"compression_type must be CompressionType object but was (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/filebasedsource.py","lineNumber":120,"sourceCode":"        specified.\n      IOError: when the file pattern specified yields an empty\n        result.\n    \"\"\"\n\n    if not isinstance(file_pattern, (str, ValueProvider)):\n      raise TypeError(\n          '%s: file_pattern must be of type string'\n          ' or ValueProvider; got %r instead' %\n          (self.__class__.__name__, file_pattern))\n\n    if isinstance(file_pattern, str):\n      file_pattern = StaticValueProvider(str, file_pattern)\n    self._pattern = file_pattern\n\n    self._concat_source = None\n    self._min_bundle_size = min_bundle_size\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    self._compression_type = compression_type\n    self._splittable = splittable\n    if validate and file_pattern.is_accessible():\n      self._validate()\n\n  def display_data(self):\n    return {\n        'file_pattern': DisplayDataItem(\n            str(self._pattern), label=\"File Pattern\"),\n        'compression': DisplayDataItem(\n            str(self._compression_type), label='Compression Type')\n    }\n\n  @check_accessible(['_pattern'])\n  def _get_concat_source(self) -> concat_source.ConcatSource:\n    if self._concat_source is None:","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/filebasedsource.py#L102-L138","documentation":"FileBasedSource.__init__ validates compression_type against CompressionTypes.is_valid_compression_type; non-enum values raise TypeError. Like the sink-side check, it forces callers to use CompressionTypes constants (AUTO, UNCOMPRESSED, GZIP, BZIP2) rather than arbitrary values.","triggerScenarios":"Constructing FileBasedSource or a subclass (e.g. ReadFromText's underlying source) with compression_type='gzip', None, or another non-member value.","commonSituations":"String vs enum confusion as in 2800; code migrated from libraries that accept string compression names.","solutions":["Pass a CompressionTypes member, e.g. CompressionTypes.GZIP","Use CompressionTypes.AUTO to infer from the file suffix","Convert strings via apache_beam.io.CompressionTypes mapping before constructing the source"],"exampleFix":"// before\nFileBasedSource('gs://b/data.json.gz', coder, compression_type='gzip')\n// after\nfrom apache_beam.io import CompressionTypes\nFileBasedSource('gs://b/data.json.gz', coder, compression_type=CompressionTypes.GZIP)","handlingStrategy":"validation","validationCode":"from apache_beam.io import CompressionTypes\nif not CompressionTypes.is_valid_compression_type(compression_type):\n    raise ValueError(f'use a CompressionTypes member, got {compression_type!r}')","typeGuard":"def is_compression_type(v) -> bool:\n    return CompressionTypes.is_valid_compression_type(v)","tryCatchPattern":null,"preventionTips":["Use enum members (CompressionTypes.GZIP/BZIP2/UNCOMPRESSED/AUTO) only","Prefer higher-level reader options that accept strings and normalize them","Map legacy string names to CompressionTypes at config load time"],"tags":["python","apache-beam","io","type-mismatch","compression"],"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-14T16:17:12.679Z"}