Skip to content

πŸ› Fix incorrect selection of root when app and router defined in same file#9

Merged
savannahostrowski merged 4 commits intomainfrom
fix-wrong-root
Jan 14, 2026
Merged

πŸ› Fix incorrect selection of root when app and router defined in same file#9
savannahostrowski merged 4 commits intomainfrom
fix-wrong-root

Conversation

@savannahostrowski
Copy link
Copy Markdown
Member

Closes #7

This PR addresses a bug where we were incorrectly selecting the wrong root instead of the FastAPI app when both were in the same file.

The fix here is to prioritize FastAPI apps over APIRouter for parent selection, filter routers by owners (e.g. app or router; note that this is currently called object on RouteInfo and I will rename accordingly in a follow up PR), and then explicitly check if router is defined locally in the same file when resolving include_router before looking for imports.

I've also added a new fixture to handle this case.

@savannahostrowski savannahostrowski added the bug Something isn't working label Jan 14, 2026
Copy link
Copy Markdown
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

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

Great! πŸš€

@savannahostrowski savannahostrowski merged commit 841cd00 into main Jan 14, 2026
6 of 7 checks passed
@savannahostrowski savannahostrowski deleted the fix-wrong-root branch January 14, 2026 22:23
@buurro
Copy link
Copy Markdown
Member

buurro commented Jan 15, 2026

πŸ’―

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong root router selected when FastAPI app and APIRouter defined in same file

3 participants