Skip to content

Commit

Permalink
Add support for unsetting LoadJobConfig schema (#9077)
Browse files Browse the repository at this point in the history
  • Loading branch information
plamut authored and tswast committed Aug 22, 2019
1 parent 2ab105b commit a279630
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,10 @@ def schema(self):

@schema.setter
def schema(self, value):
if value is None:
self._del_sub_prop("schema")
return

if not all(hasattr(field, "to_api_repr") for field in value):
raise ValueError("Schema items must be fields")
_helpers._set_sub_prop(
Expand Down
13 changes: 13 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,19 @@ def test_schema_setter(self):
config._properties["load"]["schema"], {"fields": [full_name_repr, age_repr]}
)

def test_schema_setter_unsetting_schema(self):
from google.cloud.bigquery.schema import SchemaField

config = self._get_target_class()()
config._properties["load"]["schema"] = [
SchemaField("full_name", "STRING", mode="REQUIRED"),
SchemaField("age", "INTEGER", mode="REQUIRED"),
]

config.schema = None
self.assertNotIn("schema", config._properties["load"])
config.schema = None # no error, idempotent operation

def test_schema_update_options_missing(self):
config = self._get_target_class()()
self.assertIsNone(config.schema_update_options)
Expand Down

0 comments on commit a279630

Please sign in to comment.