Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery PATCH Precondition check failed

I'm using BigQuery Python Client version google-cloud-bigquery==2.15.0 and sometimes when I update (PATCH) a table via:

client.update_table(table, ["labels", "description"])

I got the following error

PreconditionFailed('PATCH 
https://bigquery.googleapis.com/bigquery/v2/projects/my-proj/datasets/my-ds/tables/my-table?prettyPrint=false
: Precondition check failed.')

There is a closed issue https://github.com/googleapis/google-cloud-python/issues/5588 on Github related to this. Is has been resolved in a PR in 2018. But I'm still getting the error.

Any idea? Should I just upgrade to the latest version?

like image 365
hzitoun Avatar asked Jul 03 '26 20:07

hzitoun


1 Answers

I've encounter a similar situation, out of the blue I started getting PRECONDITION_FAILED: 412 errors on updating schemas via bq_client.update_table(table, ["schema"]) with just one new column while before everything worked fine. I found out that the reason for this error was the fact that I were updating the table via DDL:

table = self.bq_client.get_table(table_ref)
...
sql = f"ALTER TABLE `{table_name}` DROP COLUMN {field.name}"
self.execute_query(sql)
...
table = self.bq_client.update_table(table, ["schema"])

to work around the error I added re-fetching the table's schema:

table = self.bq_client.get_table(table_ref)
table = self.bq_client.update_table(table, ["schema"])

after that everything started working fine

like image 86
Shrike Avatar answered Jul 06 '26 09:07

Shrike