Skip to content

Commit 42db145

Browse files
committed
Add handling of missing properties SchemaField.from_api_repr
1 parent ddaa9a0 commit 42db145

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bigquery/google/cloud/bigquery/schema.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ def from_api_repr(cls, api_repr):
5656
google.cloud.biquery.schema.SchemaField:
5757
The ``SchemaField`` object.
5858
"""
59+
# Handle optional properties with default values
60+
mode = api_repr.get('mode', 'NULLABLE')
61+
fields = api_repr.get('fields', ())
5962
return cls(
6063
field_type=api_repr['type'].upper(),
61-
fields=[cls.from_api_repr(f) for f in api_repr.get('fields', ())],
62-
mode=api_repr['mode'].upper(),
64+
fields=[cls.from_api_repr(f) for f in fields],
65+
mode=mode.upper(),
6366
name=api_repr['name'],
6467
)
6568

0 commit comments

Comments
 (0)