Repository navigation
Cancel the BigQuery job when BigQueryToBigQueryOperator is killed - #75101
Conversation
shahar1
left a comment
There was a problem hiding this comment.
The change mirrors BigQueryToGCSOperator.on_kill from #74564: the job ID is now generated before insert_job, so on_kill can cancel the copy job while the synchronous wait is in progress. force_rerun=True keeps every attempt on a fresh job, and because this operator has no reattach_states, defaulting cancel_on_kill to True does not break any retry or reattach path. Tests cover both cancel_on_kill values and the new job_id argument to insert_job.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Airflow handles maintainer review:
Contributing guide.
BigQueryToBigQueryOperatorhad noon_kill, so killing the task left the copy job running in BigQuery. It also letinsert_jobgenerate the job ID while waiting for the job, so there was no ID to cancel.This generates the job ID before submitting the job, adds a
cancel_on_killargument (defaultTrue), and adds anon_killthat cancels the job. This follows #74564, which did the same forBigQueryToGCSOperator. The job ID is generated withforce_rerun=True, so every attempt still submits a new job, and its format becomesairflow_<dag_id>_<task_id>_<run_after>_<hash>like the other BigQuery operators.Users who relied on the job finishing after a kill can set cancel_on_kill=False.
Testing
I ran a
BigQueryToBigQueryOperatorwithexecution_timeout=timedelta(seconds=20). When the timeout hits,on_killnow cancels the copy job, as the task log shows.Before this change the operator had no
on_kill, so nothing cancelled the job when the task timed out and it kept running in BigQuery.Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.