Skip asset-change registration for tasks with no outlets#68687
Merged
dstandish merged 1 commit intoJun 18, 2026
Conversation
TaskInstance.register_asset_changes_in_db runs on every task-success state transition. For a task that declares no outlet assets and emits no outlet events -- the common case -- the method still executed its body and issued an AssetModel SELECT with empty IN () clauses before doing nothing useful. Return early when both task_outlets and outlet_events are empty, avoiding that round-trip on the hot path that gates scheduling the next task. Signed-off-by: Daniel Standish <daniel.standish@astronomer.io> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
uranusjr
approved these changes
Jun 17, 2026
dstandish
marked this pull request as ready for review
June 18, 2026 15:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TaskInstance.register_asset_changes_in_dbruns on every task-success state transition (from the execution APIPATCH .../statehandler). For a task that declares no outlet assets and emits no outlet events — the common case — the method still executed its full body, including anAssetModelSELECT whoseIN (...)clauses are all empty, before ultimately doing nothing.This adds an early return when both
task_outletsandoutlet_eventsare empty, eliminating that database round-trip. It sits on the task-completion path, which gates how quickly the next task can be scheduled.Detail
airflow-core/src/airflow/models/taskinstance.py: early-return guard at the top ofregister_asset_changes_in_db.payloads_by_asset, theAssetModellookup, the per-key_registercalls, and the alias path) derives fromtask_outlets/outlet_events, so when both are empty the method is already a no-op — this just makes that explicit and cheap.Tests
Added
test_register_asset_changes_in_db_no_outlets_is_a_noop, which asserts (viaassert_queries_count(0)) that no queries are issued for a task with no outlets. Existing asset-registration / partition tests continue to pass.