apache/beam · error · TypeError

Unexpected schema argument: %s.

Error message

Unexpected schema argument: %s.

What it means

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.

Source

Thrown at sdks/python/apache_beam/io/gcp/bigquery_tools.py:1746

    schema (str, dict, ~apache_beam.io.gcp.internal.clients.bigquery.\
bigquery_v2_messages.TableSchema):
      The schema to be used if the BigQuery table to write has to be created.
      This can either be a dict or string or in the TableSchema format.

  Returns:
    Dict[str, Any]: The schema to be used if the BigQuery table to write has
    to be created but in the dictionary format.
  """
  if (isinstance(schema, (dict, value_provider.ValueProvider)) or
      callable(schema) or schema is None):
    return schema
  elif isinstance(schema, str):
    table_schema = get_table_schema_from_string(schema)
    return table_schema_to_dict(table_schema)
  elif isinstance(schema, bigquery.TableSchema):
    return table_schema_to_dict(schema)
  else:
    raise TypeError('Unexpected schema argument: %s.' % schema)


def get_bq_tableschema(schema):
  """Convert the table schema to a TableSchema object.

  Args:
    schema (str, dict, ~apache_beam.io.gcp.internal.clients.bigquery.\
bigquery_v2_messages.TableSchema):
      The schema to be used if the BigQuery table to write has to be created.
      This can either be a dict or string or in the TableSchema format.

  Returns:
    ~apache_beam.io.gcp.internal.clients.bigquery.\
bigquery_v2_messages.TableSchema: The schema as a TableSchema object.
  """
  if (isinstance(schema,
                 (bigquery.TableSchema, value_provider.ValueProvider)) or
      callable(schema) or schema is None):

View on GitHub (pinned to 12126d8942)

Solutions

  1. Convert legacy apitools TableSchema to dict manually or upgrade to the google-cloud-bigquery TableSchema type.
  2. Pass the schema as a JSON string or dict instead, e.g. json.dumps of the schema, which is a supported input.
  3. For client.get_table().schema (list of SchemaField), build a dict {'fields': [f.to_api_repr() for f in schema]} first.

Example fix

// before
get_dict_table_schema(table.schema)  # list[SchemaField] -> TypeError

// after
schema_dict = get_dict_table_schema({"fields": [f.to_api_repr() for f in table.schema]})
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(schema, (dict, str, bigquery.TableSchema)):
    schema = {'fields': [f.to_api_repr() for f in schema]}  # list of SchemaField

Type guard

def is_supported_schema(s):
    return isinstance(s, (dict, str, bigquery.TableSchema))

Try / catch

try:
    d = get_dict_table_schema(schema)
except TypeError:
    d = get_dict_table_schema({'fields': [f.to_api_repr() for f in schema]})

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/6ea78b10eaeaa712. Report an issue: GitHub.