Skip to content
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

Job already exists #738

Closed
nitishxp opened this issue Jul 7, 2021 · 4 comments · Fixed by #751
Closed

Job already exists #738

nitishxp opened this issue Jul 7, 2021 · 4 comments · Fixed by #751
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@nitishxp
Copy link

nitishxp commented Jul 7, 2021

Python: 3.9 Cloud function runtime

Lib:
google-cloud-bigquery==2.15.0
google-auth==1.30.0
google-api-python-client==2.7.0

"/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/client.py", line 3149, in query query_job._begin(retry=retry, timeout=timeout) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/job/query.py", line 1044, in _begin super(QueryJob, self)._begin(client=client, retry=retry, timeout=timeout) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/job/base.py", line 461, in _begin api_response = client._call_api( File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/client.py", line 685, in _call_api return call() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/api_core/retry.py", line 285, in retry_wrapped_func return retry_target( File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/api_core/retry.py", line 188, in retry_target return target() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/_http.py", line 483, in api_request raise exceptions.from_http_response(response) google.api_core.exceptions.Conflict: 409 POST https://bigquery.googleapis.com/bigquery/v2/projects/<project_id>/jobs?prettyPrint=false: Already Exists: Job <project>:US.<Job_id>(job ID: <Job_id>)

I got the following error in one of production environment, its first time i have encountered this error.

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Jul 7, 2021
@plamut plamut added the type: question Request for information or clarification. Not an issue. label Jul 8, 2021
@plamut
Copy link
Contributor

plamut commented Jul 8, 2021

@nitishxp Does your application run queries (and create query jobs behind the scenes) by explicitly passing the job_id argument? Could it be that the same "create query job" request was sent twice in a short time span using the same job_id?

@nitishxp
Copy link
Author

nitishxp commented Jul 8, 2021

@plamut

No I don't do any of those things

Below snippet code I use

job_config = bigquery.QueryJobConfig() 
job_config.destination = dest_tbl_ref
job_config.write_disposition = bigquery.WriteDisposition.WRITE_APPEND
svtt_job = gbq.query(view_query, job_config=job_config).job_id

Traceback (most recent call last): File "/workspace/common/functions.py", line 55, in wrapper response = wrapped_func(*args, **kwargs) File "/workspace/main.py", line 370, in bq_load job_id = <function_name>) File "/workspace/main.py", line 242, in <function_name> svtt_job = gbq.query(view_query, job_config=job_config) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/client.py", line 3149, in query query_job._begin(retry=retry, timeout=timeout) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/job/query.py", line 1044, in _begin super(QueryJob, self)._begin(client=client, retry=retry, timeout=timeout) File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/job/base.py", line 461, in _begin api_response = client._call_api( File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/bigquery/client.py", line 685, in _call_api return call() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/api_core/retry.py", line 285, in retry_wrapped_func return retry_target( File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/api_core/retry.py", line 188, in retry_target return target() File "/layers/google.python.pip/pip/lib/python3.8/site-packages/google/cloud/_http.py", line 483, in api_request raise exceptions.from_http_response(response) google.api_core.exceptions.Conflict: 409 POST

@plamut
Copy link
Contributor

plamut commented Jul 8, 2021

@nitishxp I see, interesting. There's indeed nothing special about the way the query is run.

@tswast Have you seen this before? Could it happen that the server receives the request successfully, but the client does not know that because the response gets lost (or happens just before the timeout expires), and thus the client retries the very same request, even though it already succeeded?

@tswast
Copy link
Contributor

tswast commented Jul 8, 2021

@tswast Have you seen this before? Could it happen that the server receives the request successfully, but the client does not know that because the response gets lost (or happens just before the timeout expires), and thus the client retries the very same request, even though it already succeeded?

I haven't seen it before, but it is something we anticipate can happen. I suspect this issue was disguised before we started retrying connection/transport-layer errors.

We have implemented the fix for this in Java. I guess you just missed that part of the spec when we did the Python client implementation.

https://github.com/googleapis/java-bigquery/blob/e755470ad3699eee8816f55cdec4dd995cf85d52/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java#L385-L401

@tswast tswast added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: question Request for information or clarification. Not an issue. labels Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants