{"record":{"id":"acebcac667e8ec9d","repo":"apache/beam","slug":"file-path-prefix-must-be-a-string-or-valueprovider-got-r","errorCode":null,"errorMessage":"file_path_prefix must be a string or ValueProvider;got %r instead","messagePattern":"file_path_prefix must be a string or ValueProvider;got %r instead","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/filebasedsink.py","lineNumber":90,"sourceCode":"      mime_type='application/octet-stream',\n      compression_type=CompressionTypes.AUTO,\n      *,\n      max_records_per_shard=None,\n      max_bytes_per_shard=None,\n      skip_if_empty=False,\n      convert_fn=None,\n      triggering_frequency=None):\n    \"\"\"\n     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):","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/filebasedsink.py#L72-L108","documentation":"FileBasedSink's constructor requires file_path_prefix to be either a str or a runtime ValueProvider; anything else (bytes, pathlib.Path, None, int) raises TypeError with this message. This ensures the sink works both at construction time and during pipeline translation where templates resolve values dynamically.","triggerScenarios":"Passing pathlib.Path, bytes from os.fsencode, or None as file_path_prefix to WriteToText/CustomSink; computing the prefix into a non-string object in a dataflow template.","commonSituations":"Using Path objects from pathlib for 'modern' style; str.format mistakes yielding non-str; config parsed as bytes.","solutions":["Convert with str(file_path_prefix) before constructing the sink","Wrap dynamic values in apache_beam.options.value_provider.StaticValueProvider or RuntimeValueProvider","Validate the prefix type at config-load time"],"exampleFix":"// before\nsink = WriteToText(Path('/out/results'), shard_name_template='-SSS-of-NNN')\n// after\nsink = WriteToText(str(Path('/out/results')), shard_name_template='-SSS-of-NNN')","handlingStrategy":"type-guard","validationCode":"if not isinstance(file_path_prefix, (str, ValueProvider)):\n    file_path_prefix = str(file_path_prefix)","typeGuard":"from apache_beam.options.value_provider import ValueProvider\ndef is_valid_path_prefix(p):\n    return isinstance(p, (str, ValueProvider)) and bool(p)","tryCatchPattern":"try:\n    sink = WriteToText(file_path_prefix, ...)\nexcept TypeError as e:\n    if 'file_path_prefix' in str(e):\n        sink = WriteToText(str(file_path_prefix), ...)\n    else:\n        raise","preventionTips":["Cast pathlib.Path to str at config boundaries","Keep template-driven values as ValueProvider, not other types","Validate sink arguments when loading pipeline options"],"tags":["beam","sink","type-error"],"backgroundTag":"type-mismatch","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"}