-
Notifications
You must be signed in to change notification settings - Fork 322
Closed
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.Issues related to the googleapis/python-bigquery API.type: docsImprovement to the documentation for an API.Improvement to the documentation for an API.
Description
Environment details
-
API: BigQuery
-
OS type and version:
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04 LTS Release: 20.04 Codename: focal
-
Python version and virtual environment information:
$ python3 --version Python 3.8.2
-
google-cloud-bigquery version:
$ pip show google-cloud-bigquery Name: google-cloud-bigquery Version: 1.24.0 Summary: Google BigQuery API client library Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python Author: Google LLC Author-email: googleapis-packages@google.com License: Apache 2.0 Location: /home/REDACTED/.local/lib/python3.8/site-packages Requires: protobuf, google-api-core, google-cloud-core, google-auth, google-resumable-media, six Required-by:
Steps to reproduce
- Have or create a table in BigQuery
- Try to create it again using
client.create_table() - Confirm that the raised expression is
google.api_core.exceptions.Conflict- One would expect it to be
google.api_core.exceptions.AlreadyExists - Checked
client.delete_table()with a non-existent table and the result isgoogle.api_core.exceptions.NotFound
- One would expect it to be
Code example
Slightly modified version of https://cloud.google.com/bigquery/docs/tables#python
from google.cloud import bigquery
from google.api_core.exceptions import AlreadyExists, Conflict
# Construct a BigQuery client object.
client = bigquery.Client()
# TODO(developer): Set table_id to the ID of the table to create.
table_id = "your-project.your_dataset.your_table_name"
table = bigquery.Table(table_id)
table = client.create_table(table) # Make an API request.
try:
table = client.create_table(table) # Make an API request. Second time.
except AlreadyExists:
print("Caught google.api_core.exceptions.AlreadyExists")
except Conflict:
print("Caught google.api_core.exceptions.Conflict")
table = client.create_table(table) # Make an API request. Third time for Stack TraceStack trace
$ /usr/bin/python3 REDACTED/example.py
Caught google.api_core.exceptions.Conflict
Traceback (most recent call last):
File "REDACTED/example.py", line 19, in <module>
table = client.create_table(table) # Make an API request. Third time for Stack Trace
File "/home/REDACTED/.local/lib/python3.8/site-packages/google/cloud/bigquery/client.py", line 543, in create_table
api_response = self._call_api(
File "/home/REDACTED/.local/lib/python3.8/site-packages/google/cloud/bigquery/client.py", line 556, in _call_api
return call()
File "/home/REDACTED/.local/lib/python3.8/site-packages/google/api_core/retry.py", line 281, in retry_wrapped_func
return retry_target(
File "/home/REDACTED/.local/lib/python3.8/site-packages/google/api_core/retry.py", line 184, in retry_target
return target()
File "/home/REDACTED/.local/lib/python3.8/site-packages/google/cloud/_http.py", line 423, in api_request
raise exceptions.from_http_response(response)
google.api_core.exceptions.Conflict: 409 POST https://bigquery.googleapis.com/bigquery/v2/projects/REDACTED/datasets/REDACTED/tables: Already Exists: Table REDACTED:REDACTED.your_table_nameMetadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.Issues related to the googleapis/python-bigquery API.type: docsImprovement to the documentation for an API.Improvement to the documentation for an API.