{"record":{"id":"3432377838ff1a0f","repo":"apache/beam","slug":"s-file-pattern-must-be-of-type-string-or-valueprovider-got-r","errorCode":null,"errorMessage":"%s: file_pattern must be of type string or ValueProvider; got %r instead","messagePattern":"(.+?): file_pattern must be of type string or ValueProvider; got %r instead","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/filebasedsource.py","lineNumber":108,"sourceCode":"        :data:`True` by the user, :class:`FileBasedSource` may choose to not\n        split the file, for example, for compressed files where currently it is\n        not possible to efficiently read a data range without decompressing the\n        whole file.\n      validate (bool): Boolean flag to verify that the files exist during the\n        pipeline creation time.\n\n    Raises:\n      TypeError: when **compression_type** is not valid or if\n        **file_pattern** is not a :class:`str` or a\n        :class:`~apache_beam.options.value_provider.ValueProvider`.\n      ValueError: when compression and splittable files are\n        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()","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/filebasedsource.py#L90-L126","documentation":"FileBasedSource.__init__ requires file_pattern to be a str or a ValueProvider; anything else raises TypeError. ValueProvider support allows runtime-templated patterns (e.g. --input=gs://bucket/*.json) in Dataflow templates.","triggerScenarios":"Passing a list of paths, a pathlib.Path, bytes, or None as file_pattern to ReadFromText/FileBasedSource subclasses.","commonSituations":"Users pass a list ['gs://.../a.json','gs://.../b.json'] expecting multi-path reads; migrating scripts that pass Path objects; template authors bypassing ValueProvider.","solutions":["Pass a single glob string, e.g. 'gs://bucket/input/*.json'","Convert non-str values: str(path) for pathlib.Path, or wrap runtime values in StaticValueProvider/RuntimeValueProvider","To read multiple patterns, create one source per pattern or union the PCollection results"],"exampleFix":"// before\nsource = ReadFromText(['gs://b/a.json', 'gs://b/b.json'])\n// after\nsource = ReadFromText('gs://b/*.json')  # or read each pattern and flatten","handlingStrategy":"type-guard","validationCode":"if not isinstance(file_pattern, (str, ValueProvider)):\n    file_pattern = str(file_pattern)  # or join the list into a glob","typeGuard":"def is_valid_file_pattern(p) -> bool:\n    return isinstance(p, (str, ValueProvider))","tryCatchPattern":"try:\n    _ = ReadFromText(file_pattern)\nexcept TypeError as e:\n    if 'file_pattern must be' in str(e):\n        file_pattern = str(file_pattern)","preventionTips":["Pass glob strings, not lists or Path objects","Convert pathlib.Path with str() before constructing sources","Use ValueProvider for runtime-parameterized input paths"],"tags":["python","apache-beam","io","source","type-mismatch"],"backgroundTag":"invalid-constructor-argument","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"}