Repository navigation
Update the docs recommending dag.test() for custom operator tests - #71542
Merged
Merged
Conversation
Contributor
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
potiuk
pushed a commit
that referenced
this pull request
Aug 17, 2026
…or tests (#71542) (cherry picked from commit 297b0c7) Co-authored-by: Amogh Desai <[email protected]>
potiuk
pushed a commit
that referenced
this pull request
Aug 17, 2026
…or tests (#71542) (#71587) (cherry picked from commit 297b0c7) Co-authored-by: Amogh Desai <[email protected]>
vatsrahul1001
pushed a commit
that referenced
this pull request
Sep 7, 2026
…or tests (#71542) (#71587) (cherry picked from commit 297b0c7) Co-authored-by: Amogh Desai <[email protected]>
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.
Was generative AI tooling used to co-author this PR?
Our unit testing docs recommend a pattern that cannot work today. The best practices doc
tells you to build a Dag in memory and call
dag.test()on it, butdag.test()creates a real Dag run, which requires the Dag to be serialized in the metadata database. A Dag built inside a test function is in no Dag bundle, so nothingserializes it and the call raises:
For someone upgrading 3.1 to 3.2 or 3.3, they can hit above after Airflow 3.2 removed
TaskInstance.run()andTaskInstance.render_templates()(#59835) and they might go looking for a replacement.Changes:
best-practices.rst: replace the custom-operator example with directexecute()/poke()calls, addrender_template_fields()and a deferrablevariant, and name the removed
TaskInstancemethods alongside theirreplacements so a search for them lands here.
core-concepts/debug.rst: state the two prerequisites fordag.test()(amigrated database, a Dag file inside a configured bundle) and quote the error
you get when they are not met.
howto/custom-operator.rst: add a testing section. Someone writing a customoperator reads this page, finds nothing about testing, and goes looking
elsewhere.
tutorial/fundamentals.rst: correct the claim thatairflow dags testruns"without registering any state in the database". It creates a Dag run and
records task state.
The underlying confusion the docs never addressed:
dag.test()is an integration tool needing a database and a Dag on disk, whileexecute()is the unit-test tool. The docs blurred the two, so readers reached for the wrong one.Verification
Installed 3.1.0 and 3.3.0 in clean venvs and ran a custom operator and sensor
both ways:
dag.test()airflow dags testTaskInstance.run{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.