Skip to content

Commit a279630

Browse files
plamuttswast
authored andcommitted
Add support for unsetting LoadJobConfig schema (#9077)
1 parent 2ab105b commit a279630

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

bigquery/google/cloud/bigquery/job.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,10 @@ def schema(self):
11601160

11611161
@schema.setter
11621162
def schema(self, value):
1163+
if value is None:
1164+
self._del_sub_prop("schema")
1165+
return
1166+
11631167
if not all(hasattr(field, "to_api_repr") for field in value):
11641168
raise ValueError("Schema items must be fields")
11651169
_helpers._set_sub_prop(

bigquery/tests/unit/test_job.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,19 @@ def test_schema_setter(self):
15041504
config._properties["load"]["schema"], {"fields": [full_name_repr, age_repr]}
15051505
)
15061506

1507+
def test_schema_setter_unsetting_schema(self):
1508+
from google.cloud.bigquery.schema import SchemaField
1509+
1510+
config = self._get_target_class()()
1511+
config._properties["load"]["schema"] = [
1512+
SchemaField("full_name", "STRING", mode="REQUIRED"),
1513+
SchemaField("age", "INTEGER", mode="REQUIRED"),
1514+
]
1515+
1516+
config.schema = None
1517+
self.assertNotIn("schema", config._properties["load"])
1518+
config.schema = None # no error, idempotent operation
1519+
15071520
def test_schema_update_options_missing(self):
15081521
config = self._get_target_class()()
15091522
self.assertIsNone(config.schema_update_options)

0 commit comments

Comments
 (0)