fix(fastapi): use effective_route_context path for prefixed routers#6572
Merged
Conversation
The fix handles the case where FastAPI >= 0.137 stores the
prefix-resolved path in scope["fastapi"]["effective_route_context"] instead of scope["route"].path, so transactions/segments now show the full /api/users/{user_id} path instead of the unprefixed
/users/{user_id}.
Additionally, in the case of the `strawberry` framework without a specified path, this would fallback to using `generic FastAPI request` instead of using the prefix provided in the router (like `graphql` in the test cases.
Fixes PY-2530
Fixes #6571
Member
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 784e401. Configure here.
alexander-alderman-webb
approved these changes
Jun 15, 2026
Contributor
Codecov Results 📊✅ 90590 passed | ⏭️ 6031 skipped | Total: 96621 | Pass Rate: 93.76% | Execution Time: 320m 11s 📊 Comparison with Base Branch
➖ Removed Tests (4)View removed tests
All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 2421 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 29.67% 89.75% +60.08%
==========================================
Files 192 192 —
Lines 23615 23619 +4
Branches 8130 8132 +2
==========================================
+ Hits 7007 21198 +14191
- Misses 16608 2421 -14187
- Partials 654 1340 +686Generated by Codecov Action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FastAPI >= 0.137 stores the prefix-resolved path in
scope["fastapi"]["effective_route_context"]instead ofscope["route"].path, so transactions/segments were showing the unprefixed/users/{user_id}instead of the full/api/users/{user_id}for routers mounted with a prefix.This fix prefers
effective_route_context.pathwhen available, falling back toroute.pathfor older FastAPI versions.Fixes PY-2530
Fixes #6571