{"record":{"id":"3bf42c2784b0f9cb","repo":"apache/beam","slug":"bigquery-job-failed-error-result","errorCode":null,"errorMessage":"BigQuery job {} failed. Error Result: {}","messagePattern":"BigQuery job (.+?) failed\\. Error Result: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery_tools.py","lineNumber":699,"sourceCode":"\n    Args:\n      job_reference: bigquery.JobReference instance.\n      sleep_duration_sec: Specifies the delay in seconds between retries.\n      max_retries: The total number of times to retry. If equals to 0,\n        the function waits forever.\n\n    Raises:\n      `RuntimeError`: If the job is FAILED or the number of retries has been\n        reached.\n    \"\"\"\n    retry = 0\n    while True:\n      retry += 1\n      job = self.get_job(\n          job_reference.projectId, job_reference.jobId, job_reference.location)\n      _LOGGER.info('Job %s status: %s', job.id, job.status.state)\n      if job.status.state == 'DONE' and job.status.errorResult:\n        raise RuntimeError(\n            'BigQuery job {} failed. Error Result: {}'.format(\n                job_reference.jobId, job.status.errorResult))\n      elif job.status.state == 'DONE':\n        return True\n      else:\n        time.sleep(sleep_duration_sec)\n        if max_retries != 0 and retry >= max_retries:\n          raise RuntimeError('The maximum number of retries has been reached')\n\n  @retry.with_exponential_backoff(\n      num_retries=MAX_RETRIES,\n      retry_filter=retry.retry_on_server_errors_and_timeout_filter)\n  def _get_query_results(\n      self,\n      project_id,\n      job_id,\n      page_token=None,\n      max_results=10000,","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L681-L717","documentation":"Raised by BigQueryWrapper.wait_for_bq_job when polling shows the BigQuery job reached state DONE with a non-empty status.errorResult — i.e. BigQuery itself reported the job failed (bad SQL, quota, missing table, permissions, etc.). Beam surfaces the server's errorResult verbatim as a RuntimeError.","triggerScenarios":"wait_for_bq_job(job_reference, ...) called by _execute_query or _export_files when the submitted query or export job fails server-side; inspect job.status.errorResult for the actual reason.","commonSituations":"Invalid SQL syntax in a query; source table missing or renamed; per-user quota or slot exhaustion; dataset-level IAM changes removing bigquery.jobs.create; load jobs failing schema mismatch.","solutions":["Read the errorResult message in the exception and fix the underlying BigQuery job error (SQL, schema, quota).","Validate the query with dry-run (client query with dry_run=True) before submitting.","Check the job in the BigQuery console / bq CLI ('bq show -j <job_id>') for detailed error stack.","Verify IAM permissions (bigquery.jobs.create, data read) and quota limits for the project/location."],"exampleFix":"// before\nclient.query('SELCT * FROM ds.t')  # typo causes job failure\n\n// after\nclient.query('SELECT * FROM ds.t')","handlingStrategy":"try-catch","validationCode":"# dry-run the query before submitting a real job\ndry_run = client.query(sql, job_config=bigquery.QueryJobConfig(dry_run=True, use_query_cache=False))\nprint(f'query will process {dry_run.total_bytes_processed} bytes')","typeGuard":"def job_succeeded(job):\n    return job.status.state == 'DONE' and not job.status.errorResult","tryCatchPattern":"try:\n    wrapper.wait_for_bq_job(job_ref, sleep_duration_sec=10)\nexcept RuntimeError as e:\n    if 'BigQuery job' in str(e) and 'failed' in str(e):\n        handle_bq_failure(job_ref.jobId, str(e))  # inspect errorResult, alert, retry with fixed input\n    else:\n        raise","preventionTips":["Dry-run queries in CI to catch SQL/schema errors before production","Monitor errorResult reasons (rateLimitExceeded, quotaExceeded, notFound) and set alerts","Verify dataset IAM permissions before deploying pipeline changes","Check the job in the BQ console ('bq show -j') for detailed error info"],"tags":["bigquery","job-failure","remote","python"],"backgroundTag":"api-error-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}