Skip to content

Fix airflowctl showing a traceback instead of the server error on 5xx - #70841

Merged
henry3260 merged 2 commits into
apache:mainfrom
rjgoyln:fix/airflowctl-read-body-before-parsing-5xx
Aug 1, 2026
Merged

henry3260 merged 2 commits into
apache:mainfrom
rjgoyln:fix/airflowctl-read-body-before-parsing-5xx

Conversation

@rjgoyln

@rjgoyln rjgoyln commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ServerResponseError.from_response() parsed JSON from 5xx responses before reading the body, causing httpx.ResponseNotRead in response hooks.
This prevented the intended ServerResponseError from being raised and broke retries for server errors.

Changes

  • Read the response body before handling 4xx/5xx responses.
  • Format 5xx JSON errors consistently with 4xx.
  • Add a streaming-response test helper to reproduce unread-body behavior.
  • Add tests covering JSON 5xx error parsing and retry behavior.

Notes

The JSON 5xx path previously had no test coverage because existing tests used text=responses. The new tests fail on main with httpx.ResponseNotRead.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    Generated-by: Claude Code (Opus 5)

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

httpx runs response event hooks before it reads the response body, so any
hook that parses the body has to read it first. The 5xx path did not, so a
JSON server error surfaced as a raw ResponseNotRead traceback rather than
the message the API server sent. That exception is also not an
HTTPStatusError, so the retry layer never classified it as retryable and
5xx responses were never retried.
The lower bound of the 4xx check was already guaranteed by the early return
above it, and both branches built the same exception differing only in the
word Client or Server.
@henry3260
henry3260 merged commit eef1b97 into apache:main Aug 1, 2026
97 checks passed
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: airflow-ctl/v0-1-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
✅ airflow-ctl/v0-1-test PR Link

henry3260 pushed a commit that referenced this pull request Aug 2, 2026
… the server error on 5xx (#70841) (#70910)

(cherry picked from commit eef1b97)

Co-authored-by: rjgoyln <[email protected]>
shahar1 pushed a commit that referenced this pull request Nov 19, 2026
… the server error on 5xx (#70841) (#70910)

(cherry picked from commit eef1b97)

Co-authored-by: rjgoyln <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants