Skip to content

Commit 1491e1b

Browse files
committed
Fix client.patch_table
tableId is a required argument of the patch method. Also, there's no need to pass a tableReference in the body. Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 88d99de commit 1491e1b

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

bigquery/client.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,13 @@ def patch_table(self, dataset, table, schema, project_id=None):
735735

736736
body = {
737737
'schema': {'fields': schema},
738-
'tableReference': {
739-
'tableId': table,
740-
'projectId': project_id,
741-
'datasetId': dataset
742-
}
743738
}
744739

745740
try:
746741
result = self.bigquery.tables().patch(
747742
projectId=project_id,
748743
datasetId=dataset,
744+
tableId=table,
749745
body=body
750746
).execute(num_retries=self.num_retries)
751747
if self.swallow_results:

bigquery/tests/test_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,9 +1913,6 @@ def setUp(self):
19131913
self.client = client.BigQueryClient(self.mock_bq_service, self.project)
19141914
self.body = {
19151915
'schema': {'fields': self.schema},
1916-
'tableReference': {
1917-
'tableId': self.table, 'projectId': self.project,
1918-
'datasetId': self.dataset}
19191916
}
19201917
self.expiration_time = 1437513693000
19211918

@@ -1941,7 +1938,8 @@ def test_table_patch_failed(self):
19411938
self.client.swallow_results = True
19421939

19431940
self.mock_tables.patch.assert_called_with(
1944-
projectId=self.project, datasetId=self.dataset, body=self.body)
1941+
projectId=self.project, datasetId=self.dataset,
1942+
tableId=self.table, body=self.body)
19451943

19461944
self.mock_tables.patch.return_value.execute. \
19471945
assert_called_with(num_retries=0)
@@ -1968,7 +1966,8 @@ def test_table_patch_success(self):
19681966
self.client.swallow_results = True
19691967

19701968
self.mock_tables.patch.assert_called_with(
1971-
projectId=self.project, datasetId=self.dataset, body=self.body)
1969+
projectId=self.project, datasetId=self.dataset,
1970+
tableId=self.table, body=self.body)
19721971

19731972
self.mock_tables.patch.return_value.execute. \
19741973
assert_called_with(num_retries=0)

0 commit comments

Comments
 (0)