Skip to content

Migrate Execution API GET /dags/{dag_id} to async DB session - #77206

Open
rafaelwilliem wants to merge 1 commit into
apache:mainfrom
rafaelwilliem:migrate-execution-get-dag-async
Open

rafaelwilliem wants to merge 1 commit into
apache:mainfrom
rafaelwilliem:migrate-execution-get-dag-async

Conversation

@rafaelwilliem

@rafaelwilliem rafaelwilliem commented Nov 17, 2026 •

Copy link
Copy Markdown

Migrate the Execution API GET /execution/dags/{dag_id} (get_dag) endpoint from synchronous SessionDep to AsyncSessionDep so database reads yield the event loop without occupying a threadpool worker.

Instead of calling session.get(DagModel, dag_id) (which selects all 35 DagModel columns and lazily queries dag_model.tags), project only the 7 DagModel columns required by DagResponse and DagTag.name, avoiding full DagModel and DagTag ORM entity hydration and lazy-loading on the async session.

related: #67799


Was generative AI tooling used to co-author this PR?
  • Yes — Google Antigravity (Argon & Hydrogen)

Generated-by: Google Antigravity following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: #77206.significant.rst, in airflow-core/newsfragments.

Release threadpool workers during database reads on GET /execution/dags/{dag_id} and project only the columns required by DagResponse instead of hydrating full DagModel and DagTag ORM entities.

@fat-catTW fat-catTW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR

@rafaelwilliem

Copy link
Copy Markdown
Author

hi @fat-catTW, is there an update in regards of this PR?

@Dev-iL Dev-iL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review Summary

This PR migrates the Execution API GET /execution/dags/{dag_id} endpoint from synchronous SessionDep to AsyncSessionDep, with proper column projection to avoid full ORM entity hydration.

What was checked

Code review (against airflow-async-endpoints skill)

  • ✅ Uses AsyncSessionDep (existing database infrastructure)
  • ✅ Awaits all I/O (session.execute, session.scalars)
  • ✅ No route-level commit added (transaction ownership preserved)
  • ✅ Projects only the 7 DagModel columns required by DagResponse
  • ✅ Tags queried separately as names only (no DagTag entity hydration)
  • ✅ No synchronous helpers called on the async path

Tests

  • All 5 existing tests in test_dags.py pass
  • New test test_get_dag_does_not_hydrate_orm_entities passes
    • Uses loaded_as_persistent listener to verify no DagModel or DagTag entities are hydrated
    • Confirms the column projection is working as intended

Benchmark (event-loop blocking)

Measured event-loop stall time for both base (sync) and PR (async) versions:

Version Median Stall Max Stall
Base (sync, main) 2.03-3.11 ms 3.60-6.18 ms
PR (async) 3.47-3.54 ms 3.94-4.37 ms

The async version shows a small fixed increase in median stall (~0.4-1.5 ms), which is within the expected range described in the async endpoints skill: "Expect a small fixed increase at every size: async statement execution and result handling now run on the loop instead of in a worker thread, about 1 ms per request."

The key benefit is that the async version yields the event loop during database I/O, allowing other requests to be processed concurrently. The sync version runs on a threadpool worker, which holds the GIL and doesn't actually block the event loop, but it also doesn't scale as well under concurrent load.

Conclusion

The migration is correct and follows the established patterns for async endpoint conversions in Airflow. The column projection avoids the overhead of full entity hydration, and the benchmark confirms acceptable event-loop blocking behavior.

Recommendation: Approve and merge.

Dev-iL

This comment was marked as duplicate.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants