apache/beam · error · ValueError
Encountered an unsupported mode: {mode!r}
Error message
Encountered an unsupported mode: {mode!r} What it means
bq_field_to_type maps a BigQuery field to a Python type hint based on its mode; only NULLABLE (or None/''), REPEATED, and REQUIRED are handled. Any other mode string (e.g. from an outdated API or hand-built schema) falls through to this unsupported-mode error.
Source
Thrown at sdks/python/apache_beam/io/gcp/bigquery_schema_tools.py:116
Args:
field: The BigQuery type name (e.g., 'STRING', 'DATE').
mode: The field mode ('NULLABLE', 'REPEATED', 'REQUIRED').
type_overrides: Optional mapping of BigQuery type names (uppercase)
to Python types. These override the default mappings.
Returns:
The corresponding Python type hint.
"""
effective_types = {**BIG_QUERY_TO_PYTHON_TYPES, **(type_overrides or {})}
if mode == 'NULLABLE' or mode is None or mode == '':
return Optional[effective_types[field]]
elif mode == 'REPEATED':
return Sequence[effective_types[field]]
elif mode == 'REQUIRED':
return effective_types[field]
else:
raise ValueError(f"Encountered an unsupported mode: {mode!r}")
def convert_to_usertype(
table_schema, selected_fields=None, type_overrides=None):
"""Convert a BigQuery table schema to a user type.
Args:
table_schema: A BQ schema of type TableSchema
selected_fields: if not None, the subset of fields to consider
type_overrides: Optional mapping of BigQuery type names (uppercase)
to Python types.
Returns:
A ParDo transform that converts dictionaries to the user type.
"""
usertype = generate_user_type_from_bq_schema(
table_schema, selected_fields, type_overrides)
return beam.ParDo(BeamSchemaConversionDoFn(usertype))View on GitHub (pinned to 12126d8942)
Solutions
- Ensure every schema field has mode set to one of 'NULLABLE', 'REQUIRED', or 'REPEATED' (case-sensitive).
- Default missing modes to 'NULLABLE' when building the schema dict: field.setdefault('mode', 'NULLABLE').
- Normalize/strip mode strings before calling, e.g. field['mode'].strip().upper().
- Inspect the schema source (console export, REST response) for unexpected mode values and correct them.
Example fix
# before
fields = [{'name': 'x', 'type': 'STRING'}]
convert_to_usertype({'fields': fields}) # mode is None
# after
fields = [{'name': 'x', 'type': 'STRING', 'mode': 'NULLABLE'}]
convert_to_usertype({'fields': fields}) Defensive patterns
Strategy: validation
Validate before calling
VALID_MODES = {'NULLABLE', 'REQUIRED', 'REPEATED'}
for f in schema['fields']:
mode = (f.get('mode') or 'NULLABLE').strip().upper()
if mode not in VALID_MODES:
raise ValueError(f"invalid mode {f.get('mode')!r} for field {f['name']!r}") Type guard
def has_valid_mode(field):
return field.get('mode') in ('NULLABLE', 'REQUIRED', 'REPEATED') Try / catch
try:
usertype = convert_to_usertype(schema)
except ValueError as e:
if 'unsupported mode' in str(e):
raise SchemaConfigError('fix field mode (NULLABLE/REQUIRED/REPEATED)') from e
raise Prevention
- Always set mode explicitly on every schema field
- Normalize mode casing/whitespace when importing schemas from external tools
- Use BigQuery's real API response as schema source instead of hand-typed dicts
When it happens
Trigger: Calling bq_field_to_type(field['type'], field['mode'], overrides) — directly or via convert_to_usertype / generate_user_type_from_bq_schema — with mode values like None, 'NULLABLE ' (trailing space), lowercase 'nullable', or fabricated modes.
Common situations: Hand-crafted schema dicts missing the 'mode' key (passing None); schemas exported by tools that use different mode casing; trimming/whitespace issues when copying schema JSON from BigQuery console or docs.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unexpected schema argument: %s.
- Both a query and an output type of 'BEAM_ROW' were specified
- Unknown BigQuery field mode: {}
- Encountered an unsupported type: {field['type']!r}
- Table %s:%s.%s requires a schema. None can be inferred becau
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/25732df982e5cfd6.
Report an issue: GitHub.