Repository navigation
Adding DAG bundle_name to AirflowParsingContext - #77552
Open
jroachgolf84 wants to merge 7 commits into
Open
jroachgolf84 wants to merge 7 commits into
jroachgolf84 wants to merge 7 commits into
Conversation
… parsing context to it can be used outside of get_current_context
jroachgolf84
requested review from
amoghrajesh,
ashb,
ephraimbuddy and
jedcunningham
as code owners
November 24, 2026 15:49
bundle_name to Parsing Contextbundle_name to AirflowParsingContext
Collaborator
Author
|
cc: @jedcunningham |
amoghrajesh
reviewed
Dec 2, 2026
amoghrajesh
left a comment
Contributor
There was a problem hiding this comment.
Why can't you set the context inside BundleDagBag, and expose bundle_name as a property instead of a tuple field? That fixes the backcompat issue and the issue where it is None on cli path
Collaborator
Author
|
@amoghrajesh, I went ahead and implemented your feedback, should be all set to re-review. |
This branch has not been deployed
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.
Description
DAG code running at parse time can call
get_parsing_context()to readdag_idandtask_id, but it has no way to find out which DAG bundle it is being parsed from.This PR adds a
bundle_nameproperty toAirflowParsingContext.BundleDagBagsets it before parsing, so it is available on every path that parses a file from a bundle: the Dag processor (including callbacks), a task re-parsing its DAG file before running, and CLI commands such asairflow dags testandairflow dags reserialize. It isNonewhen a file is not loaded from a bundle.Like
dag_idandtask_id, the value stays set after parsing, so it is also available while the task runs. Becausebundle_nameis a property rather than a new tuple field,AirflowParsingContextkeeps its shape and existing code that unpacks it positionally (dag_id, task_id = get_parsing_context()) keeps working.Example Use Case
Testing
These changes were tested via unit tests added to the following files:
airflow-core/tests/unit/dag_processing/test_dagbag.py:BundleDagBagsets the bundle name for Dag code to read, and clears a value left over from an earlier parse when no bundle name is given.task-sdk/tests/task_sdk/definitions/test_context.py:bundle_namereads the current value, and the context still unpacks intodag_id, task_id.Was generative AI tooling used to co-author this PR?
Generated-by: [Claude Opus 5.5] following the guidelines