@@ -985,6 +985,8 @@ def test_update_table_autodetect_schema(self):
985985 TABLE_NAME = "test_table"
986986 set_schema = [bigquery .SchemaField ("username" , "STRING" , mode = "NULLABLE" )]
987987 table_arg = Table (dataset .table (TABLE_NAME ))
988+
989+ # Create an external_config and include it in the table arguments
988990 external_config = bigquery .ExternalConfig (bigquery .ExternalSourceFormat .AVRO )
989991 external_config .source_uris = SOURCE_URIS_AVRO
990992 external_config .reference_file_schema_uri = REFERENCE_FILE_SCHEMA_URI_AVRO
@@ -1001,22 +1003,19 @@ def test_update_table_autodetect_schema(self):
10011003
10021004 # Update table with schema autodetection
10031005 updated_table_arg = Table (dataset .table (TABLE_NAME ))
1004- updated_external_config = bigquery .ExternalConfig (
1005- bigquery .ExternalSourceFormat .AVRO
1006- )
1007- updated_external_config .source_uris = SOURCE_URIS_AVRO
1008- updated_external_config .reference_file_schema_uri = (
1009- REFERENCE_FILE_SCHEMA_URI_AVRO
1010- )
1006+
1007+ # Update the external_config and include it in the table arguments
1008+ updated_external_config = copy .deepcopy (external_config )
10111009 updated_external_config .autodetect = True
10121010 updated_external_config .schema = None
10131011 updated_table_arg .external_data_configuration = updated_external_config
10141012
1013+ # PATCH call with autodetect_schema=True to trigger schema inference
10151014 updated_table = Config .CLIENT .update_table (
10161015 updated_table_arg , ["external_data_configuration" ], autodetect_schema = True
10171016 )
10181017
1019- # The updated table shlould have a schema inferred from the reference
1018+ # The updated table should have a schema inferred from the reference
10201019 # file, which has all four fields.
10211020 expected_schema = [
10221021 bigquery .SchemaField ("username" , "STRING" , mode = "NULLABLE" ),
0 commit comments