-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigQuery: client.create_table raises Conflict instead of AlreadyExists #123
Comments
Also, there does not seem to be a way to distinguish between the two types of |
@jpuig-mind @skelliest Agreed with you statement, it returns http code rather than grpc_status_code because As you can see below in source code also, to handle exception use python-bigquery/google/cloud/bigquery/client.py Lines 549 to 552 in be86de3
|
@HemangChothani Thanks for the clarification. For clarity then, shouldn't the exception handling be something more like the following? except google.api_core.exceptions.Conflict as e:
if not exists_ok:
raise google.api_core.exceptions.AlreadyExists(e.message, e.errors, e.response)
return self.get_table(table.reference, retry=retry) I suggest this solution since it's the BigQuery client that should hold the "if Conflict then AlreadyExists" knowledge, and take the guesswork off the hands of the user. I apologise if I made any mistake, python is not my first language. Cheers! |
@jpuig-mind I think it's bit difficult to bifurcate code snippet: if not 200 <= response.status_code < 300:
raise exceptions.from_http_response(response) and then another exception raised what you suggest: except google.api_core.exceptions.Conflict as e:
if not exists_ok:
raise google.api_core.exceptions.AlreadyExists(e.message, e.errors, e.response) I don't think it's good idea, but still i would like to ask @plamut |
@plamut any suggestion? |
@HemangChothani If I understand correctly, the concern is that we first create an exception from the HTTP response (in Ideally, we should only translate the exception once (in It would probably also be beneficial to keep the link with the original exception: except api_core.exceptions.Conflict as exc:
if not exists_ok:
rebranded_error = api_core.exceptions.AlreadyExists(exc.message, exc.errors, exc.response)
six.raise_from(rebranded_error, exc) Or did I misunderstand the question? |
@plamut Thanks for the help,appreciate it. The main concern is how to distinguish errors between |
@HemangChothani Distinguishing based on a message string is indeed not ideal and 100% future-proof, but if that's our best bet, we might have no other choice, if we want to fix this for the users ... :/ Since it's probably not too much work, I'd say we at least open a PR for better visibility and discuss there whether relying on the error message is still "good enough" for our needs. |
@paul1319 Ok, I will open PR soon, thank you. |
As per the comment received on PR #131 (comment) i think googler disagree with the solution and suggest to leave as it is as same in other manual libraries which is based on HTTP. @plamut Could i close the PR and issue? |
@HemangChothani It appears so, yes. Let's be consistent with other manual libraries then, and instead explain this behavior in a docstring as mentioned in the same comment. |
Environment details
API: BigQuery
OS type and version:
Python version and virtual environment information:
google-cloud-bigquery version:
Steps to reproduce
client.create_table()
google.api_core.exceptions.Conflict
google.api_core.exceptions.AlreadyExists
client.delete_table()
with a non-existent table and the result isgoogle.api_core.exceptions.NotFound
Code example
Slightly modified version of https://cloud.google.com/bigquery/docs/tables#python
Stack trace
The text was updated successfully, but these errors were encountered: