Skip to content

Cancel the BigQuery job when BigQueryToBigQueryOperator is killed - #75101

Merged
shahar1 merged 1 commit into
apache:mainfrom
yuseok89:bigquery-to-bigquery-cancel-on-kill
Oct 25, 2026
Merged

shahar1 merged 1 commit into
apache:mainfrom
yuseok89:bigquery-to-bigquery-cancel-on-kill

Conversation

@yuseok89

Copy link
Copy Markdown
Contributor

BigQueryToBigQueryOperator had no on_kill, so killing the task left the copy job running in BigQuery. It also let insert_job generate 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_kill argument (default True), and adds an on_kill that cancels the job. This follows #74564, which did the same for BigQueryToGCSOperator. The job ID is generated with force_rerun=True, so every attempt still submits a new job, and its format becomes airflow_<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 BigQueryToBigQueryOperator with execution_timeout=timedelta(seconds=20). When the timeout hits, on_kill now cancels the copy job, as the task log shows.

image

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?
  • Yes (please specify the tool below)
    • Claude Code (Opus 5.5)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

@boring-cyborg boring-cyborg Bot added area:providers provider:google Google (including GCP) related issues labels Oct 19, 2026
@yuseok89
yuseok89 marked this pull request as ready for review October 19, 2026 22:06
@yuseok89
yuseok89 requested a review from shahar1 as a code owner October 19, 2026 22:06

@olegkachur-e olegkachur-e left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shahar1
shahar1 merged commit a1976c5 into apache:main Oct 25, 2026
142 checks passed
@shahar1 shahar1 mentioned this pull request Nov 4, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants