Repository navigation
Description
Under which category would you file this issue?
Providers
Apache Airflow version
main (dev)
What happened and how to reproduce it?
In deferrable mode, BigQueryValueCheckOperator and BigQueryIntervalCheckOperator fail with the message Job running while the BigQuery job is still executing normally.
BigQueryAsyncHook.get_job_status() returns the job state as-is for any job that isn't DONE, so a job in progress reports either "pending" or "running":
airflow/providers/google/src/airflow/providers/google/cloud/hooks/bigquery.py
Lines 2381 to 2385 in e92147c
| if job.state == "DONE": | |
| if job.error_result: | |
| return {"status": "error", "message": job.error_result["message"]} | |
| return {"status": "success", "message": "Job completed"} | |
| return {"status": str(job.state).lower(), "message": "Job running"} |
Both triggers treat only "pending" as "still in progress" and send every other status, including "running", to the error branch:
BigQueryValueCheckTrigger.run():
airflow/providers/google/src/airflow/providers/google/cloud/triggers/bigquery.py
Lines 687 to 695 in e92147c
| elif response_from_hook["status"] == "pending": | |
| self.log.info("Query is still running...") | |
| self.log.info("Sleeping for %s seconds.", self.poll_interval) | |
| await asyncio.sleep(self.poll_interval) | |
| else: | |
| yield TriggerEvent( | |
| {"status": "error", "message": response_from_hook["message"], "records": None} | |
| ) | |
| return |
BigQueryIntervalCheckTrigger.run():
airflow/providers/google/src/airflow/providers/google/cloud/triggers/bigquery.py
Lines 584 to 590 in e92147c
| elif ( | |
| first_job_response_from_hook["status"] == "pending" | |
| or second_job_response_from_hook["status"] == "pending" | |
| ): | |
| self.log.info("Query is still running...") | |
| self.log.info("Sleeping for %s seconds.", self.poll_interval) | |
| await asyncio.sleep(self.poll_interval) |
Repro:
- Use
BigQueryValueCheckOperator(..., deferrable=True)(orBigQueryIntervalCheckOperator) with a query that takes longer than onepoll_interval. - The job moves to
RUNNING, and the trigger yields{"status": "error", "message": "Job running"}. - The task fails, even though the query would have succeeded.
There is a second problem in BigQueryIntervalCheckTrigger: the error event always uses the second job's message:
airflow/providers/google/src/airflow/providers/google/cloud/triggers/bigquery.py
Lines 591 to 595 in e92147c
| else: | |
| yield TriggerEvent( | |
| {"status": "error", "message": second_job_response_from_hook["message"], "data": None} | |
| ) | |
| return |
When the first job fails and the second succeeds, the task fails with Job completed and the real error is lost.
The other triggers in the same file use if success / elif error / else keep polling, so they don't have this problem. For example, BigQueryInsertJobTrigger.run():
airflow/providers/google/src/airflow/providers/google/cloud/triggers/bigquery.py
Lines 187 to 212 in e92147c
| if job_status["status"] == "success": | |
| self.log.info("BigQuery Job succeeded") | |
| yield TriggerEvent( | |
| { | |
| "job_id": self.job_id, | |
| "status": job_status["status"], | |
| "message": job_status["message"], | |
| } | |
| ) | |
| return | |
| elif job_status["status"] == "error": | |
| self.log.info("BigQuery Job failed: %s", job_status) | |
| yield TriggerEvent( | |
| { | |
| "status": job_status["status"], | |
| "message": job_status["message"], | |
| } | |
| ) | |
| return | |
| else: | |
| self.log.info( | |
| "Bigquery job status is %s. Sleeping for %s seconds.", | |
| job_status["status"], | |
| self.poll_interval, | |
| ) | |
| await asyncio.sleep(self.poll_interval) |
Existing tests only mock the "pending" status, never "running", which is why this wasn't caught:
airflow/providers/google/tests/unit/google/cloud/triggers/test_bigquery.py
Lines 720 to 724 in e92147c
| async def test_interval_check_trigger_pending(self, mock_job_status, caplog, interval_check_trigger): | |
| """ | |
| Tests that the BigQueryIntervalCheckTrigger do not fire while a query is still running. | |
| """ | |
| mock_job_status.return_value = {"status": "pending", "message": "Job pending"} |
airflow/providers/google/tests/unit/google/cloud/triggers/test_bigquery.py
Lines 816 to 820 in e92147c
| async def test_value_check_op_trigger_pending(self, mock_job_status, caplog, value_check_trigger): | |
| """ | |
| Tests BigQueryValueCheckTrigger only fires once the query execution reaches a successful state. | |
| """ | |
| mock_job_status.return_value = {"status": "pending", "message": "Job pending"} |
What you think should happen instead?
Any status that is neither success nor error (including running) should keep polling, matching the other triggers in the same module. BigQueryIntervalCheckTrigger should report the message of the job that actually failed.
Operating System
No response
Deployment
None
Apache Airflow Provider(s)
No response
Versions of Apache Airflow Providers
apache-airflow-providers-google 22.5.0
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
bingqin2 commentedon Sep 30, 2026
I'd like to fix this. @roykoand, you left the PR box unticked, so I'm picking it up; say so if you would rather do it yourself.
The fix gives both triggers the order the other triggers in the module already use: success, then error, then keep polling for any other status.
BigQueryIntervalCheckTriggeralso reports the job that failed. One more effect of the same branch: while one job has failed and the other is stillpending, the interval check keeps polling until the other job finishes, instead of failing right away. The PR covers that too.Cover long-running jobs in the deferrable BigQuery check system test (#…