{"record":{"id":"ddcc235055b25bea","repo":"apache/beam","slug":"s-gcs-location-must-be-of-type-string-or-valueprovider-got-r","errorCode":null,"errorMessage":"%s: gcs_location must be of type string or ValueProvider; got %r instead","messagePattern":"(.+?): gcs_location must be of type string or ValueProvider; got %r instead","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery.py","lineNumber":3069,"sourceCode":"    self.method = method or ReadFromBigQuery.Method.EXPORT\n    self.use_native_datetime = use_native_datetime\n    self.output_type = output_type\n    self.query_output_schema = query_output_schema\n    self._args = args\n    self._kwargs = kwargs\n    if timeout is not None:\n      self._kwargs['timeout'] = timeout\n\n    if self.method == ReadFromBigQuery.Method.EXPORT \\\n        and self.use_native_datetime is True:\n      raise TypeError(\n          'The \"use_native_datetime\" parameter cannot be True for EXPORT.'\n          ' Please set the \"use_native_datetime\" parameter to False *OR*'\n          ' set the \"method\" parameter to ReadFromBigQuery.Method.DIRECT_READ.')\n\n    if gcs_location and self.method == ReadFromBigQuery.Method.EXPORT:\n      if not isinstance(gcs_location, (str, ValueProvider)):\n        raise TypeError(\n            '%s: gcs_location must be of type string'\n            ' or ValueProvider; got %r instead' %\n            (self.__class__.__name__, type(gcs_location)))\n      if isinstance(gcs_location, str):\n        gcs_location = StaticValueProvider(str, gcs_location)\n\n    if self.output_type == 'BEAM_ROW' and self._kwargs.get('query',\n                                                           None) is not None:\n      if self.query_output_schema is None:\n        raise ValueError(\n            \"Both a query and an output type of 'BEAM_ROW' were specified \"\n            \"without a query_output_schema. When using a query, you must \"\n            \"provide query_output_schema so the output schema can be \"\n            \"determined without reading an existing table. The schema should \"\n            \"be a BigQuery schema dict, e.g. \"\n            \"{'fields': [{'name': 'col', 'type': 'STRING', 'mode': 'NULLABLE'}\"\n            \", ...]}, or a TableSchema object.\")\n","sourceCodeStart":3051,"sourceCodeEnd":3087,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery.py#L3051-L3087","documentation":"When using ReadFromBigQuery with the EXPORT method, gcs_location identifies the GCS path for export files and must be a plain string or a Beam ValueProvider. The library raises TypeError in __init__ (bigquery.py:3069) for any other type so misconfiguration fails fast before pipeline submission.","triggerScenarios":"Passing gcs_location as a list, dict, pathlib.Path, gs:// URI object, None-wrapped custom type, or any non-str/non-ValueProvider while method=EXPORT.","commonSituations":"Using pathlib.Path('gs://bucket/tmp') instead of its str form; passing a google.cloud.storage Bucket/Blob object; wrapping the location in a container; dynamic templates need ValueProvider but users pass a runtime-parameterized custom callable.","solutions":["Convert the location to a string: gcs_location='gs://my-bucket/tmp'","Wrap runtime values in StaticValueProvider(str, gcs_location) or RuntimeValueProvider","If using pathlib.Path, call str(path) before passing"],"exampleFix":"// before\nfrom pathlib import Path\nReadFromBigQuery(table=t, gcs_location=Path('gs://bucket/tmp'))\n// after\nReadFromBigQuery(table=t, gcs_location='gs://bucket/tmp')","handlingStrategy":"type-guard","validationCode":"assert isinstance(gcs_location, (str, ValueProvider)), type(gcs_location)","typeGuard":"def is_valid_gcs_location(x):\n    return isinstance(x, (str, ValueProvider))","tryCatchPattern":"try:\n    transform = ReadFromBigQuery(..., gcs_location=gcs)\nexcept TypeError as e:\n    if 'gcs_location' in str(e):\n        gcs = str(gcs)","preventionTips":["Always pass gs:// URIs as plain strings","Wrap runtime/template values in ValueProvider subclasses","Never pass Path or client-library objects where strings are documented"],"tags":["python","apache-beam","bigquery","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-14T16:17:12.679Z"}