diff --git a/bigquery/tests/system.py b/bigquery/tests/system.py index 84d38ac09e25..8749707b62da 100644 --- a/bigquery/tests/system.py +++ b/bigquery/tests/system.py @@ -939,15 +939,6 @@ def test_load_table_from_json_basic_use(self): self.assertEqual(table.num_rows, 2) def test_load_table_from_json_schema_autodetect(self): - # Use schema with NULLABLE fields, because schema autodetection - # defaults to field mode NULLABLE. - table_schema = ( - bigquery.SchemaField("name", "STRING", mode="NULLABLE"), - bigquery.SchemaField("age", "INTEGER", mode="NULLABLE"), - bigquery.SchemaField("birthday", "DATE", mode="NULLABLE"), - bigquery.SchemaField("is_awesome", "BOOLEAN", mode="NULLABLE"), - ) - json_rows = [ {"name": "John", "age": 18, "birthday": "2001-10-15", "is_awesome": False}, {"name": "Chuck", "age": 79, "birthday": "1940-03-10", "is_awesome": True}, @@ -959,13 +950,21 @@ def test_load_table_from_json_schema_autodetect(self): Config.CLIENT.project, dataset_id ) - # Create the table before loading so that schema mismatch errors are - # identified. + # Use schema with NULLABLE fields, because schema autodetection + # defaults to field mode NULLABLE. + table_schema = ( + bigquery.SchemaField("name", "STRING", mode="NULLABLE"), + bigquery.SchemaField("age", "INTEGER", mode="NULLABLE"), + bigquery.SchemaField("birthday", "DATE", mode="NULLABLE"), + bigquery.SchemaField("is_awesome", "BOOLEAN", mode="NULLABLE"), + ) + # create the table before loading so that the column order is predictable table = retry_403(Config.CLIENT.create_table)( Table(table_id, schema=table_schema) ) self.to_delete.insert(0, table) + # do not pass an explicit job config to trigger automatic schema detection load_job = Config.CLIENT.load_table_from_json(json_rows, table_id) load_job.result() diff --git a/bigquery/tests/unit/test_client.py b/bigquery/tests/unit/test_client.py index 0c1a33bf971f..71886354c8ba 100644 --- a/bigquery/tests/unit/test_client.py +++ b/bigquery/tests/unit/test_client.py @@ -5635,6 +5635,7 @@ def test_load_table_from_json_non_default_args(self): SchemaField("adult", "BOOLEAN"), ] job_config = job.LoadJobConfig(schema=schema) + job_config._properties["load"]["unknown_field"] = "foobar" load_patch = mock.patch( "google.cloud.bigquery.client.Client.load_table_from_file", autospec=True @@ -5666,6 +5667,8 @@ def test_load_table_from_json_non_default_args(self): assert sent_config.source_format == job.SourceFormat.NEWLINE_DELIMITED_JSON assert sent_config.schema == schema assert not sent_config.autodetect + # all properties should have been cloned and sent to the backend + assert sent_config._properties.get("load", {}).get("unknown_field") == "foobar" # Low-level tests