Idempotent router(s) [draft] #1622
Open
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.
Problem Overview
The existing router system had several fundamental issues that prevented router reuse and caused unexpected behavior:
1. Routers are Single-Use
Once a
Routeris mounted to an API viaapi.add_router(),Router.apiis set, making the router unusable with other APIs. Attempting to reuse a router raisesConfigError.2. Mutation Leaks Through Decorators
When
add_router()is called, decorators, auth, tags, and throttle settings are mutated directly on the router. These mutations persist and affect all future mounts:3. Issue #1597: Child Routers Don't Inherit Decorators
Child routers added after parent mounting don't inherit parent's decorators because
build_routers()was called atadd_router()time, before children were fully configured.4. URL Naming Clashes
Mounting the same router multiple times within one API produces duplicate URL names, causing Django URL resolution issues.