Thanks to visit codestin.com
Credit goes to github.com

Skip to content

✨ Support mounting StaticFiles to sub-routers#13944

Open
YuriiMotov wants to merge 4 commits intofastapi:masterfrom
YuriiMotov:issue-10180-mount-to-router
Open

✨ Support mounting StaticFiles to sub-routers#13944
YuriiMotov wants to merge 4 commits intofastapi:masterfrom
YuriiMotov:issue-10180-mount-to-router

Conversation

@YuriiMotov
Copy link
Member

@YuriiMotov YuriiMotov commented Jul 28, 2025

For now if you try mounting the sub-application to APIRouter it will be silently ignored.

See issue: #10180

This PR makes it working. At the same time mounting other apps to APIRouter will raise FastAPIError with clear error message

@YuriiMotov YuriiMotov linked an issue Jul 28, 2025 that may be closed by this pull request
@mrcghil
Copy link

mrcghil commented Jan 17, 2026

Having bumped on this silent bug today I think it is a pity that this PR has been sitting here for so long! Anything we can do to push this through?
Best,
Marco

@YuriiMotov YuriiMotov force-pushed the issue-10180-mount-to-router branch from 10b5cb1 to c6987ce Compare February 12, 2026 11:31
@YuriiMotov YuriiMotov changed the title 🗑️ Deprecate APIRouter.mount() method ✨ Support mounting StaticFiles to sub-routers Feb 12, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 12, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing YuriiMotov:issue-10180-mount-to-router (d0950a2) with master (b93c964)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (ed12105) during the generation of this report, so b93c964 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@YuriiMotov
Copy link
Member Author

Updated PR to support mounting StaticFiles to sub-routers instead of deprecating APIRouter.mount() completely

@YuriiMotov YuriiMotov marked this pull request as ready for review February 12, 2026 11:46
kimchikingdom added a commit to kimchikingdom/fastapi that referenced this pull request Feb 14, 2026
Per maintainer feedback on fastapi#14924, limit Mount propagation in
include_router() to StaticFiles only, matching the approach in fastapi#13944.

Non-StaticFiles sub-app mounts are silently ignored (not propagated)
to preserve existing behavior, since sub-applications should be mounted
directly on the root FastAPI instance.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mounting sub-applications under APIRouter

2 participants