{"record":{"id":"0d8b30da28dd1e40","repo":"apache/beam","slug":"unexpected-schema-argument-s","errorCode":null,"errorMessage":"Unexpected schema argument: %s.","messagePattern":"Unexpected schema argument: (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery.py","lineNumber":1613,"sourceCode":"  def get_table_schema(schema):\n    \"\"\"Transform the table schema into a bigquery.TableSchema instance.\n\n    Args:\n      schema: The schema to be used if the BigQuery table to write has to be\n        created. This is a dictionary object created in the WriteToBigQuery\n        transform.\n    Returns:\n      table_schema: The schema to be used if the BigQuery table to write has\n         to be created but in the bigquery.TableSchema format.\n    \"\"\"\n    if schema is None:\n      return schema\n    elif isinstance(schema, str):\n      return bigquery_tools.parse_table_schema_from_json(schema)\n    elif isinstance(schema, dict):\n      return bigquery_tools.parse_table_schema_from_json(json.dumps(schema))\n    else:\n      raise TypeError('Unexpected schema argument: %s.' % schema)\n\n  def start_bundle(self):\n    self._reset_rows_buffer()\n\n    if not self.bigquery_wrapper:\n      self.bigquery_wrapper = bigquery_tools.BigQueryWrapper(\n          client=self.test_client)\n\n    (\n        bigquery_tools.BigQueryWrapper.HISTOGRAM_METRIC_LOGGER.\n        minimum_logging_frequency_msec\n    ) = self.streaming_api_logging_frequency_sec * 1000\n\n    self._backoff_calculator = iter(\n        retry.FuzzedExponentialIntervals(\n            initial_delay_secs=0.2,\n            num_retries=self._max_retries,\n            max_delay_secs=1500))","sourceCodeStart":1595,"sourceCodeEnd":1631,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery.py#L1595-L1631","documentation":"get_table_schema converts the schema argument and only accepts None, a string (JSON), or a dict. Any other type (e.g. a pyarrow schema, an object, or a list) is rejected with TypeError so invalid schema inputs fail fast at setup time (_create_table_if_needed).","triggerScenarios":"Passing schema as something other than str/dict/None to WriteToBigQuery — e.g. a bigquery.SchemaField list, a pyarrow.Schema, or an Apache Beam schema object.","commonSituations":"Reusing a schema obtained from the google-cloud-bigquery client or from a PCollection schema without converting it to the JSON string/dict form Beam expects.","solutions":["Pass the schema as a JSON string or a dict matching the BigQuery JSON schema format.","Convert other schema representations: pyarrow.Schema -> serialize to JSON, list of SchemaField -> bigquery_tools.get_table_schema or client's to_api_repr().","Use SCHEMA_AUTODETECT constant with FILE_LOADS if you want the schema inferred."],"exampleFix":"// before\nWriteToBigQuery(table, schema=pyarrow_schema)\n// after\nWriteToBigQuery(table, schema='{\"fields\": [{\"name\": \"id\", \"type\": \"INTEGER\"}]}')\n# or schema={'fields': [{'name': 'id', 'type': 'INTEGER'}]}","handlingStrategy":"type-guard","validationCode":"assert schema is None or isinstance(schema, (str, dict)), f'schema must be None, JSON str, or dict, got {type(schema)}'","typeGuard":"def valid_bq_schema(schema):\n    return schema is None or isinstance(schema, (str, dict))","tryCatchPattern":"try:\n    _ = beam.io.WriteToBigQuery(table, schema=schema)\nexcept TypeError as e:\n    schema = json.dumps(schema_to_json(schema))  # convert then retry","preventionTips":["Always pass schema as JSON string or dict of the BigQuery JSON schema form","Convert google-cloud-bigquery SchemaField lists via to_api_repr()","Add a unit test asserting the schema type before pipeline construction"],"tags":["bigquery","python","apache-beam","schema"],"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"}