{"record":{"id":"df63b10c329eb5e3","repo":"apache/beam","slug":"compression-type-must-be-compressiontype-object-but-was-s","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/filebasedsink.py","lineNumber":99,"sourceCode":"     Raises:\n      TypeError: if file path parameters are not a :class:`str` or\n        :class:`~apache_beam.options.value_provider.ValueProvider`, or if\n        **compression_type** is not member of\n        :class:`~apache_beam.io.filesystem.CompressionTypes`.\n      ValueError: if **shard_name_template** is not of expected\n        format.\n    \"\"\"\n    if not isinstance(file_path_prefix, (str, ValueProvider)):\n      raise TypeError(\n          'file_path_prefix must be a string or ValueProvider;'\n          'got %r instead' % file_path_prefix)\n    if not isinstance(file_name_suffix, (str, ValueProvider)):\n      raise TypeError(\n          'file_name_suffix must be a string or ValueProvider;'\n          'got %r instead' % file_name_suffix)\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 shard_name_template is None:\n      shard_name_template = DEFAULT_SHARD_NAME_TEMPLATE\n    elif shard_name_template == '':\n      num_shards = 1\n    if triggering_frequency is None:\n      triggering_frequency = DEFAULT_TRIGGERING_FREQUENCY\n    if isinstance(file_path_prefix, str):\n      file_path_prefix = StaticValueProvider(str, file_path_prefix)\n    if isinstance(file_name_suffix, str):\n      file_name_suffix = StaticValueProvider(str, file_name_suffix)\n    self.file_path_prefix = file_path_prefix\n    self.file_name_suffix = file_name_suffix\n    self.num_shards = num_shards\n    self.coder = coder\n    self.shard_name_template = shard_name_template\n    self.shard_name_format = self._template_to_format(shard_name_template)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/filebasedsink.py#L81-L117","documentation":"FileBasedSink.__init__ validates that compression_type is one of the recognized members of the CompressionTypes enum (via CompressionTypes.is_valid_compression_type). A raw string like 'gzip' or an arbitrary object is rejected. The library requires an actual CompressionTypes constant so compression handling is unambiguous.","triggerScenarios":"Passing a plain string (e.g. 'gzip', 'bzip2'), None, or any non-CompressionTypes object as compression_type to a FileBasedSink subclass (e.g. WriteToText with a hand-constructed sink).","commonSituations":"Users confuse the string-based compression= parameter of WriteToText/WriteToFiles with the enum-based compression_type of the underlying sink; copied sample code uses raw strings.","solutions":["Import CompressionTypes from apache_beam.io.filebasedsink (or apache_beam.io) and pass e.g. CompressionTypes.GZIP instead of a string","Pass CompressionTypes.AUTO to let the sink infer compression from the file_name_suffix","If a string is unavoidable, map it first: CompressionTypes.validate_compression_type(compression_type)"],"exampleFix":"// before\nsink = FileBasedSink(file_path_prefix, coder, compression_type='gzip')\n// after\nfrom apache_beam.io import CompressionTypes\nsink = FileBasedSink(file_path_prefix, 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'compression_type must be a CompressionTypes member, got {compression_type!r}')","typeGuard":"def is_compression_type(v) -> bool:\n    from apache_beam.io import CompressionTypes\n    return CompressionTypes.is_valid_compression_type(v)","tryCatchPattern":null,"preventionTips":["Always import and use CompressionTypes members, never raw strings","Prefer compression= on WriteToText, which accepts strings and validates them"],"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"}