You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "juditnovak (via GitHub)" <gi...@apache.org> on 2025/12/11 12:22:29 UTC
[PR] [BUGFIX] Flush session() before processing Event Buffer [airflow]
juditnovak opened a new pull request, #59314:
URL: https://github.com/apache/airflow/pull/59314
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
closes: https://github.com/apache/airflow/issues/59074
The issue have been demonstrated on separate branch (including helper code that is not to be merged): https://github.com/juditnovak/airflow/pull/2
The fix have been demonstrated to respond to the issue (including helper code that is not to be merged): https://github.com/juditnovak/airflow/pull/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](https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/execution_time/supervisor.py)
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
4. then the supervisor returns results to the Executor, who will register the results in its Event Buffer
5. NOTE: 1.)-3.) were part of the Executor's heartbeat()/sync() calls.
6. 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.
7. 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](https://github.com/apache/airflow/blob/main/airflow-core/tests/unit/core/test_impersonation_tests.py) 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] dag.test(): Flush session() before processing Executor Event Buffer [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #59314:
URL: https://github.com/apache/airflow/pull/59314
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [BUGFIX] Flush session() before processing Event Buffer [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #59314:
URL: https://github.com/apache/airflow/pull/59314#issuecomment-3641673581
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]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-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](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) 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](https://www.apache.org/foundation/policies/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]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] dag.test(): Flush session() before processing Executor Event Buffer [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #59314:
URL: https://github.com/apache/airflow/pull/59314#issuecomment-3664992666
Ok. old issue from the past with timeout - looks good. Merging.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] dag.test(): Flush session() before processing Executor Event Buffer [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #59314:
URL: https://github.com/apache/airflow/pull/59314#issuecomment-3664996885
### Backport successfully created: v3-1-test
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>✅</td>
<td>v3-1-test</td>
<td><a href="https://github.com/apache/airflow/pull/59559"><img src="https://img.shields.io/badge/PR-59559-blue" alt="PR Link"></a></td>
</tr>
</table>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] dag.test(): Flush session() before processing Executor Event Buffer [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #59314:
URL: https://github.com/apache/airflow/pull/59314#issuecomment-3664993014
Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org