Skip to content

Fix ASYNC240 rule findings #61418

Closed

Description

@jscheffl

Apache Airflow version

main (development)

If "Other Airflow 3 version" selected, which one?

No response

What happened?

PR #61417 with upgrading Ruff version to 0.15.0 enabled rule ASYNC240 per default. Some occurrences and findings make the code not compatible.

Nevertheless the rule seems to make sense in general not blocking async code by IO requests.

What you think should happen instead?

Rule should be re-enabled and code locations should be optimized.

NOTE: It is to be decided which of the two libraries to use and it seems this is adding a new dependency. So a short cal to maintainers is needed to get a quorum which to pick.

How to reproduce

Remove exclusion of rule ASYNC240 as it was added by e3c727c in pyproject.toml, run ruff in the repo to see cases where code needs to be fixed.
Follow descriptions in https://docs.astral.sh/ruff/rules/blocking-path-method-in-async-function/#blocking-path-method-in-async-function-async240

Operating System

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added theissue type on Feb 3, 2026
  2. js0547 commented on Feb 4, 2026

    @js0547

    @jscheffl I’d like to pick this up as a first contribution if that’s okay.

  3. sawantbandita commented on Feb 4, 2026

    @sawantbandita
    Contributor

    Hi! I’m a beginner contributor and very interested in working on this issue as well. I’m happy to collaborate or take on part of the ASYNC240 fixes (e.g. identifying affected files or preparing patches/tests). Please let me know how you’d like to proceed.

  4. v4xsh commented on Feb 4, 2026

    @v4xsh

    Hi @jscheffl I’d like to work on this. I’ve looked into the ASYNC240 rule and the discussion regarding the dependency quorum for Airflow 3.

    The issue is that pathlib methods like .exists() and .is_file() are synchronous and block the event loop when called inside async functions. To re-enable the rule, we need to offload these calls to a thread or use an async filesystem wrapper.

    Regarding the library choice mentioned in the description:

    • AnyIO: We could use anyio.to_thread.run_sync to wrap the pathlib calls. This is a surgical fix that doesn't require a full filesystem refactor.
    • Trio/Aiofiles: These provide native async path objects but would add a more significant dependency for the core.

    I’m happy to implement whichever approach the maintainers prefer to get this rule re-enabled.

  5. jscheffl commented on Feb 4, 2026

    @jscheffl
    ContributorAuthor

    Thanks for the analysis. I am not a deep enought asyncio expert. Any opinions from other experts? @potiuk @ashb @dstandish @dabla ??

  6. v4xsh commented on Feb 5, 2026

    @v4xsh

    Thanks for the feedback!

    Agreed — this probably needs a maintainer call before locking in an approach. From my side, I don’t have a strong preference yet and would follow whatever direction the core team recommends.

    That said, if a low-risk default is helpful for discussion: anyio.to_thread.run_sync feels like the smallest surface-area change to unblock ASYNC240 without introducing a new async filesystem abstraction. But I’m very happy to wait for guidance from @potiuk, @ashb, @dstandish, or @dabla before moving forward.

    Let me know how you’d like to proceed.

  7. jscheffl commented on Feb 5, 2026

    @jscheffl
    ContributorAuthor

    I now had time to look to trio and anyio. I think both are valid but anyio seems to be a bit stronger maintained. If nobody has another opinion in the next 24 hours I'd propose to go with anyio. Anyio has less dependencies.

    Other opinions welcome!

  8. added a commit that references this issue on Feb 7, 2026
    55eb66b
  9. added a commit that references this issue on Feb 8, 2026
    0681126
  10. added a commit that references this issue on Feb 8, 2026
    a90ebd3
  11. added a commit that references this issue on Feb 15, 2026
    72b9e98
  12. added a commit that references this issue on Feb 22, 2026
    ccc8ec2
  13. added a commit that references this issue on Feb 27, 2026
    30e9c3b
  14. added a commit that references this issue on Mar 4, 2026
    e513906
  15. added a commit that references this issue on Mar 11, 2026
    a6c568d
  16. added a commit that references this issue on Mar 15, 2026
    88f86d7
  17. added a commit that references this issue on Mar 21, 2026
    a8b50f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions