Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery: Add support for unsetting LoadJobConfig schema #9077

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

@plamut plamut Aug 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra assignment is to catch fragile implementations such as
del self._properties["load"]["schema"]

(nope, did not do it myself, but I've seen similar bugs in the past 😆 )


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