From 42db1450c476cfe7fc5fe763d92d560f4a9652ee Mon Sep 17 00:00:00 2001 From: Alan Velasco Date: Mon, 15 Jan 2018 08:47:22 -0600 Subject: [PATCH] Add handling of missing properties SchemaField.from_api_repr --- bigquery/google/cloud/bigquery/schema.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bigquery/google/cloud/bigquery/schema.py b/bigquery/google/cloud/bigquery/schema.py index 155ffe9a159a7..f619b1cd9f2cc 100644 --- a/bigquery/google/cloud/bigquery/schema.py +++ b/bigquery/google/cloud/bigquery/schema.py @@ -56,10 +56,13 @@ def from_api_repr(cls, api_repr): google.cloud.biquery.schema.SchemaField: The ``SchemaField`` object. """ + # Handle optional properties with default values + mode = api_repr.get('mode', 'NULLABLE') + fields = api_repr.get('fields', ()) return cls( field_type=api_repr['type'].upper(), - fields=[cls.from_api_repr(f) for f in api_repr.get('fields', ())], - mode=api_repr['mode'].upper(), + fields=[cls.from_api_repr(f) for f in fields], + mode=mode.upper(), name=api_repr['name'], )