Skip to content

Attach the request to SSE errors via request_context#1073

Open
Kludex wants to merge 3 commits into
mainfrom
sse-request-context
Open

Attach the request to SSE errors via request_context#1073
Kludex wants to merge 3 commits into
mainfrom
sse-request-context

Conversation

@Kludex

@Kludex Kludex commented Jul 16, 2026

Copy link
Copy Markdown
Member

Wrap the SSE iteration in request_context so any SSEError raised while consuming the stream carries the originating request, the same way the client attaches request context to errors elsewhere (e.g. Response.aiter_raw).

Behaviour-neutral today: the only SSEError currently raised is the content-type check, which already passed request= explicitly and continues to carry it - now via the wrapper rather than the explicit argument. This is groundwork for #1071, which adds size-limit errors during iteration that should carry the request too.

Extended test_content_type_mismatch_raises to assert exc.request is set.

Review in cubic

Wrap the SSE iteration in request_context so any SSEError raised while
consuming the stream carries the originating request, matching how the
rest of the client attaches request context to errors. The content-type
check no longer needs to pass request explicitly.
@github-actions

Copy link
Copy Markdown

Docs preview:

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing sse-request-context (ec0ec4a) with main (c4e73cf)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ecd77cbfd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/httpx2/httpx2/_sse.py Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/httpx2/httpx2/_sse.py Outdated
Comment thread tests/httpx2/test_sse.py
Read the nullable _request attribute rather than the Response.request
property, which raises when no request is attached. request_context
already accepts None. Also assert the request on the async content-type
test and cover a requestless EventSource.
@Kludex
Kludex deployed to cloudflare July 16, 2026 15:51 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant