Skip to content

Clone responses returned by async side effects - #333

Closed
00200200 wants to merge 1 commit into
lundberg:masterfrom
00200200:codex/clone-async-side-effect-responses
Closed

00200200 wants to merge 1 commit into
lundberg:masterfrom
00200200:codex/clone-async-side-effect-responses

Conversation

@00200200

Copy link
Copy Markdown

An async side effect can return a response without an attached request. Router.aresolve currently skips the cloning performed by Route.resolve for synchronous side effects. When that response is reused through HTTPX MockTransport, both requests receive the same object and the second request overwrites the first response's request metadata. Calling async_handler directly also leaves response.request unset.

Clone responses without an attached request immediately after awaiting the side effect, using the existing helper. Responses with an explicit request retain their current behavior. Regression tests cover both request cases and response reuse through AsyncClient/MockTransport.

Validation on macOS/Python 3.12.11 with HTTPX 0.28.1:

  • Before the fix: two new regression cases failed; the explicit-request control passed.
  • Full suite: 324 passed, 2 optional remote pass-through tests skipped; 100% statement and branch coverage.
  • Changed-file Black 23.3.0, isort 5.13.2, flake8 7.0.0, additional Ruff rules and git diff --check passed.
  • Mypy 1.15.0 reports one existing unused type: ignore in tests/test_router.py. The same check on the unchanged base commit reports the identical error (line 341 on the base, line 384 with these tests).

Other Python versions and live remote pass-through were not tested. The full pre-commit environment was not installed.

@00200200

Copy link
Copy Markdown
Author

I am withdrawing this small test-mocking change as part of narrowing my outstanding contributions. The code remains on 00200200:codex/clone-async-side-effect-responses for reference.

@00200200 00200200 closed this Oct 26, 2026
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