The Fix
Upgrade to version 0.15.2 or later.
Based on closed encode/httpx issue #1310 · PR/commit linked
@@ -859,7 +859,7 @@ def _send_single_request(self, request: Request, timeout: Timeout) -> Response:
def on_close(response: Response) -> None:
- response.elapsed = datetime.timedelta(timer.sync_elapsed())
+ response.elapsed = datetime.timedelta(seconds=timer.sync_elapsed())
if hasattr(stream, "close"):
import httpx
client = httpx.Client()
with client.stream("GET", "https://httpbin.org/basic-auth/user/pass", auth=("user", "pass")) as r:
print(r)
print(r.elapsed)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.15.2 or later.\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n
Why This Fix Works in Production
- Trigger: The elapsed time reported was incoherent, leading to confusion in performance metrics.
- Mechanism: The elapsed time was incorrectly calculated without converting to seconds
- Why the fix works: Fixes the incorrect calculation of the elapsed time in response objects by ensuring the elapsed time is calculated in seconds. (first fixed release: 0.15.2).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- The elapsed time was incorrectly calculated without converting to seconds
- Production symptom (often without a traceback): The elapsed time reported was incoherent, leading to confusion in performance metrics.
Proof / Evidence
- GitHub issue: #1310
- Fix PR: https://github.com/encode/httpx/pull/1313
- First fixed release: 0.15.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.69
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“### Checklist - [ X] The bug is reproducible against the latest release and/or master. - [ X] There are no similar issues or pull requests to fix it yet. ### Describe the bug The elapsed argument obtained following a stream request seems co”
Failure Signature (Search String)
- The elapsed time reported was incoherent, leading to confusion in performance metrics.
Copy-friendly signature
Failure Signature
-----------------
The elapsed time reported was incoherent, leading to confusion in performance metrics.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
The elapsed time reported was incoherent, leading to confusion in performance metrics.
Minimal Reproduction
import httpx
client = httpx.Client()
with client.stream("GET", "https://httpbin.org/basic-auth/user/pass", auth=("user", "pass")) as r:
print(r)
print(r.elapsed)
Environment
- httpx: 0.15.1
What Broke
The elapsed time reported was incoherent, leading to confusion in performance metrics.
Why It Broke
The elapsed time was incorrectly calculated without converting to seconds
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.15.2 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/encode/httpx/pull/1313
First fixed release: 0.15.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use if it changes public behavior or if the failure cannot be reproduced.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
- Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.15.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.