Skip to content

Conversation

@juditnovak
Copy link
Contributor


closes: #59074

The issue have been demonstrated on separate branch (including helper code that is not to be merged): juditnovak#2

The fix have been demonstrated to respond to the issue (including helper code that is not to be merged): juditnovak#1

Root cause

The dag.test() function is using a single session throughout its lifetime. Since data is cached on the session, outdated results are retrieved.

  1. LocalExecutor executes workloads via the supervisor
  2. at the end of the task execution, the supervisor is sending an call to the Airflow API /execution/task-instances/ endpoint. This call is responsible for updating the database with the final state
  3. then the supervisor returns results to the Executor, who will register the results in its Event Buffer
  4. NOTE: 1.)-3.) were part of the Executor's heartbeat()/sync() calls.
  5. in the particularly intense dag.test() polling workflow the SchedulerJobRunner.process_executor_events() call is invoked right after, rapidly processing contents of the Executor's Event Buffer.
  6. however, at this point DB updates from API call from 2.) are not yet available on the dag.test() session. Instead a cached record is returned from an earlier update.

Testing

  • Currently I find not tests within the task-sdk targeting dag.test(). I don't know if this may be intentional?
  • I find a single Airflow unit test directly relying on the use_executor=True option
    • it is not the target of the tests, but a tool to perform other tests
  • In the supplementary material to this PR I'm providing showcase to the fix. However since the issue is related to cache expiration, I'm afraid it would be hard to reproduce with determinisic (i.e. 'non-flaky') tests.

@boring-cyborg
Copy link

boring-cyborg bot commented Dec 11, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@juditnovak juditnovak changed the title [BUGFIX] Flush session() before processing Event Buffer [BUGFIX] dag.test(): Flush session() before processing Event Buffer Dec 11, 2025
@juditnovak juditnovak changed the title [BUGFIX] dag.test(): Flush session() before processing Event Buffer [BUGFIX] dag.test(): Flush session() before processing Executor Event Buffer Dec 11, 2025
@juditnovak juditnovak changed the title [BUGFIX] dag.test(): Flush session() before processing Executor Event Buffer dag.test(): Flush session() before processing Executor Event Buffer Dec 11, 2025
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Usually we require unit tests, but dag.test is a long and not unit-testable really, and the dag.test on its own is used to run tests, so it's a bit "who tests the tester".

It would likely be great however (as a follow-up) to add a test to one of our e2e tests to make a complete run of dag_test with executor and without. Not a unit test but still should allow us to actually test the "dag.test()".

I will create an issue for that.

@potiuk potiuk force-pushed the bugfix/59074_dag_test_sync_pr branch from f47b107 to 92f3705 Compare December 11, 2025 14:54
@potiuk potiuk force-pushed the bugfix/59074_dag_test_sync_pr branch from c58b49f to 552f876 Compare December 14, 2025 07:06
@potiuk
Copy link
Member

potiuk commented Dec 17, 2025

Ok. old issue from the past with timeout - looks good. Merging.

@potiuk potiuk merged commit e7a1e57 into apache:main Dec 17, 2025
94 of 95 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 17, 2025

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@potiuk potiuk added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Dec 17, 2025
@potiuk potiuk added this to the Airflow 3.1.6 milestone Dec 17, 2025
github-actions bot pushed a commit that referenced this pull request Dec 17, 2025
…59314)

(cherry picked from commit e7a1e57)

Co-authored-by: Judit Novak <judit.novak@gmail.com>
@github-actions
Copy link

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Dec 17, 2025
…pache#59314)

(cherry picked from commit e7a1e57)

Co-authored-by: Judit Novak <judit.novak@gmail.com>
potiuk pushed a commit that referenced this pull request Dec 17, 2025
…59314) (#59559)

(cherry picked from commit e7a1e57)

Co-authored-by: Judit Novak <judit.novak@gmail.com>
FoxHelms pushed a commit to FoxHelms/airflow that referenced this pull request Dec 17, 2025
Lohith625 pushed a commit to Lohith625/airflow that referenced this pull request Dec 19, 2025
ephraimbuddy pushed a commit that referenced this pull request Jan 6, 2026
…59314) (#59559)

(cherry picked from commit e7a1e57)

Co-authored-by: Judit Novak <judit.novak@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dag.test(use_executor=True) doesn't provide the /execution API, but all executors rely on it

3 participants