Skip to content

Fix task run context crash when DagRun state is expired#66339

Merged
amoghrajesh merged 1 commit intoapache:mainfrom
astronomer:worktree-fix-dagrun-state-extraction
May 4, 2026
Merged

Fix task run context crash when DagRun state is expired#66339
amoghrajesh merged 1 commit intoapache:mainfrom
astronomer:worktree-fix-dagrun-state-extraction

Conversation

@amoghrajesh
Copy link
Copy Markdown
Contributor


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

What problem are we solving?

After session.commit(), SQLA expires all ORM instance attributes. The safe_extract_from_orm validator added in: #63916, reads attributes from insp.dict to avoid DetachedInstanceError — but expired attributes are absent from __dict__. Since DagRun._state is expired after a commit, state is silently dropped from the extracted dict, and pydantic raises a ResponseValidationError because state: DagRunState is required.

Current behaviour

Tasks fail to enter the running state with:

ResponseValidationError: Field required at ('response', 'dag_run', 'state')

Fix

When _state is absent from insp.dict but the instance is still attached (not insp.detached), fall back to accessing data._state directly — this triggers SQLA's lazy reload. This guard preserves the original fix: on a genuinely detached instance, direct access would raise DetachedInstanceError, so that case is left alone.


  • 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: {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.

@potiuk potiuk added this to the Airflow 3.2.2 milestone May 4, 2026
@potiuk potiuk added the backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch label May 4, 2026
@amoghrajesh amoghrajesh merged commit 403a1eb into apache:main May 4, 2026
141 checks passed
@amoghrajesh amoghrajesh deleted the worktree-fix-dagrun-state-extraction branch May 4, 2026 10:17
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Backport successfully created: v3-2-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-2-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request May 4, 2026
…pache#66339)

(cherry picked from commit 403a1eb)

Co-authored-by: Amogh Desai <amoghrajesh1999@gmail.com>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request May 4, 2026
…pache#66339)

(cherry picked from commit 403a1eb)

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants