{"record":{"id":"6ea78b10eaeaa712","repo":"apache/beam","slug":"unexpected-schema-argument-s-bigquery-tools","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_tools.py","lineNumber":1746,"sourceCode":"    schema (str, dict, ~apache_beam.io.gcp.internal.clients.bigquery.\\\nbigquery_v2_messages.TableSchema):\n      The schema to be used if the BigQuery table to write has to be created.\n      This can either be a dict or string or in the TableSchema format.\n\n  Returns:\n    Dict[str, Any]: The schema to be used if the BigQuery table to write has\n    to be created but in the dictionary format.\n  \"\"\"\n  if (isinstance(schema, (dict, value_provider.ValueProvider)) or\n      callable(schema) or schema is None):\n    return schema\n  elif isinstance(schema, str):\n    table_schema = get_table_schema_from_string(schema)\n    return table_schema_to_dict(table_schema)\n  elif isinstance(schema, bigquery.TableSchema):\n    return table_schema_to_dict(schema)\n  else:\n    raise TypeError('Unexpected schema argument: %s.' % schema)\n\n\ndef get_bq_tableschema(schema):\n  \"\"\"Convert the table schema to a TableSchema object.\n\n  Args:\n    schema (str, dict, ~apache_beam.io.gcp.internal.clients.bigquery.\\\nbigquery_v2_messages.TableSchema):\n      The schema to be used if the BigQuery table to write has to be created.\n      This can either be a dict or string or in the TableSchema format.\n\n  Returns:\n    ~apache_beam.io.gcp.internal.clients.bigquery.\\\nbigquery_v2_messages.TableSchema: The schema as a TableSchema object.\n  \"\"\"\n  if (isinstance(schema,\n                 (bigquery.TableSchema, value_provider.ValueProvider)) or\n      callable(schema) or schema is None):","sourceCodeStart":1728,"sourceCodeEnd":1764,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L1728-L1764","documentation":"get_dict_table_schema() accepts only dict, JSON string, or bigquery.TableSchema schemas; any other type raises TypeError 'Unexpected schema argument'. It is the dispatcher converting supported schema forms into a plain dict.","triggerScenarios":"Passing a bigquery.SchemaField list, a TableFieldSchema, a pathlib object, bytes, or None to get_dict_table_schema(); passing a protobuf-parsed schema object not of type bigquery.TableSchema.","commonSituations":"Users passing schema fetched via the legacy apitools client (TableSchema from apache_beam.io.gcp.internal.clients.bigquery) which is a different class than google.cloud.bigquery TableSchema; passing a list of SchemaField from client.get_table().schema.","solutions":["Convert legacy apitools TableSchema to dict manually or upgrade to the google-cloud-bigquery TableSchema type.","Pass the schema as a JSON string or dict instead, e.g. json.dumps of the schema, which is a supported input.","For client.get_table().schema (list of SchemaField), build a dict {'fields': [f.to_api_repr() for f in schema]} first."],"exampleFix":"// before\nget_dict_table_schema(table.schema)  # list[SchemaField] -> TypeError\n\n// after\nschema_dict = get_dict_table_schema({\"fields\": [f.to_api_repr() for f in table.schema]})","handlingStrategy":"type-guard","validationCode":"if not isinstance(schema, (dict, str, bigquery.TableSchema)):\n    schema = {'fields': [f.to_api_repr() for f in schema]}  # list of SchemaField","typeGuard":"def is_supported_schema(s):\n    return isinstance(s, (dict, str, bigquery.TableSchema))","tryCatchPattern":"try:\n    d = get_dict_table_schema(schema)\nexcept TypeError:\n    d = get_dict_table_schema({'fields': [f.to_api_repr() for f in schema]})","preventionTips":["Convert client.get_table().schema (list of SchemaField) to a dict before passing.","Pass schemas as JSON strings or dicts to stay version-agnostic.","After Beam upgrades, verify which TableSchema class your pipeline uses."],"tags":["python","apache-beam","bigquery","schema","type-error"],"backgroundTag":"invalid-argument-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"}