fix(asgi): Stop duplicating scope["root_path"] in URLs#6579
fix(asgi): Stop duplicating scope["root_path"] in URLs#6579alexander-alderman-webb wants to merge 12 commits into
scope["root_path"] in URLs#6579Conversation
Codecov Results 📊✅ 90998 passed | ⏭️ 6135 skipped | Total: 97133 | Pass Rate: 93.68% | Execution Time: 318m 48s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 2409 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.85% 89.86% +0.01%
==========================================
Files 192 192 —
Lines 23745 23748 +3
Branches 8198 8198 —
==========================================
+ Hits 21334 21339 +5
- Misses 2411 2409 -2
- Partials 1344 1344 —Generated by Codecov Action |
scope["root_path"] in URLs
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b420587. Configure here.
wahajahmed010
left a comment
There was a problem hiding this comment.
Review: #6579
Summary: Clean fix for ASGI URL duplication when scope["root_path"] is already included in scope["path"]. The approach is sound — thread a path_includes_root_path boolean through the URL construction pipeline.
✅ What works well
- Backward compatible — default is
True, preserving existing behavior for frameworks that don't include root_path in path - Framework-specific handling — correctly version-gated for Starlette (>=0.33), Quart (>=0.19), and hardcoded for Litestar/Starlite
- Test coverage — all 6 integrations tested (Django ASGI, FastAPI, Litestar, Quart, Starlette, Starlite), both span streaming and static lifecycle modes
- Clean threading — parameter flows through
_get_url→_get_request_data→_get_request_attributes→_get_transaction_name_and_source→_get_segment_name_and_source
⚠️ Potential issues
- Django ASGI test — The test sets
comm.scope["root_path"] = "/root"but Django defaults topath_includes_root_path=True. Does Django ASGI actually include root_path in path? If not, this test might pass but produce incorrect URLs in production. Worth verifying Django's ASGI behavior. - No test for
path_includes_root_path=False— The Starlette/FastAPI tests only exercise theTruepath (Starlette >= 0.33). The old behavior (False) has no dedicated test. - Edge case: empty path — When
path_includes_root_path=Trueandscope["path"]is empty, the URL would be just scheme+host with no path. Unlikely but worth noting.
Verdict
Solid PR. The core logic is correct and well-structured. The main risk is the Django default assumption — worth double-checking before merging.

Description
Add the
path_includes_root_pathboolean parameter to_get_url()and related functions.If the parameter is
True(the default),scope["path"]is considered to includescope["root_path"], wherescopeis the ASGI scope. Otherwise, the existing behavior that prependsscope["root_path"]when forming the url is preserved.Add tests to each ASGI-based integration. Some are compliant with the ASGI spec in which
scope["path"]includesscope["root_path"], while others are not. In particular, Starlite, LiterStar and old versions of Starlette and Quart are not compliant with the spec. In these cases,path_includes_root_path=Falseis set.Issues
Closes #6577
Reminders
uv run ruff.feat:,fix:,ref:,meta:)