Skip to content

fix: resolve lifecycle policy from Django's matched route - #55

Closed
mojtaba-arvin wants to merge 18 commits into
mainfrom
fix/lifecycle-resolved-route-policy
Closed

mojtaba-arvin wants to merge 18 commits into
mainfrom
fix/lifecycle-resolved-route-policy

Conversation

@mojtaba-arvin

@mojtaba-arvin mojtaba-arvin commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Problem

LifecycleMiddleware previously extracted versions in the outer request phase, before Django resolved the URL. A raw-path regex could select an earlier API-like version segment in a parent mount instead of the selected child route.

Changes

  • Move sunset short-circuiting to process_view, after URL resolution and before the selected view.
  • Resolve registered endpoint and VersionedRouter versions from the actual ResolverMatch.route using the longest complete registered route suffix, including parent URLResolver prefixes and DRF regex anchors.
  • Prefer resolver kwargs and registered route metadata over request.version/path heuristics.
  • Preserve version-wide 410 behavior for unresolved paths when exactly one distinct configured version is present; ambiguous nested paths are not guessed.
  • Keep lifecycle headers on resolved view responses, including view-generated 404s.
  • Add real Django Client and AsyncClient integration tests for nested routes, VersionedRouter metadata, request-level URLconf overrides, pre-view 410, unresolved 404/410 behavior, and view-level 404 headers.
  • Update the Reference lifecycle contract and website source-evidence anchors.

Compatibility decision

The canonical routing contract remains version-wide. For unresolved paths, legacy 410 behavior is retained only when one configured version can be identified unambiguously. When a path contains multiple distinct version segments and no route resolves, the middleware does not guess.

Verification

Latest head: 82d9ac6b43fa6008d934ef75ab9fd8e7b7dccfea.

Full CI passed

The exact head passed the complete PR gate: unit/integration tests, lint, package build, website verification, tox/workflow validation, Windows, macOS, and every configured Python/Django combination. CodeQL passed as well.

PR remains Draft pending the combined integration check with #44. No merge or ready-for-review action has been taken.

Copy link
Copy Markdown
Owner Author

Superseded by the consolidated integration PR #58, which includes this work and passed the complete required PR gate on exact head 98f79472777f9e8e0bbf78c16531d97a46ad0a3a. The consolidated change is now merged to main as a8b39343c478bb5a8afbe1de20d95a2b10630f37. Closing this focused PR to avoid leaving duplicate, already-integrated branches open; its implementation history remains in the PR conversation and the consolidated merge.

@mojtaba-arvin
mojtaba-arvin deleted the fix/lifecycle-resolved-route-policy branch November 19, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant