New issue to wemake-services/django-modern-rest by @Izcarmt95 📝…

🚀 New issue to wemake-services/django-modern-rest by @Izcarmt95
📝 Router.include() raises KeyError for a route with an empty pattern ('') (#1657)


Router.include() raises KeyError when the included router has a route with an empty pattern (path('', ...)), which is the usual way to mount a list endpoint at the router's prefix.

from dmr import Controller
from dmr.plugins.pydantic import PydanticSerializer
from dmr.routing import Router, path


class UserListController(Controller[PydanticSerializer]):
def get(self) -> str:
return 'ok'


users = Router('/users', [path('', UserListController.as_view(), name='users')])
api = Router('api')
api.include(users, namespace='users') # KeyError: '/users'

  File ".../dmr/routing.py", line 173, in include
router.metadata_for(original_path),
File ".../dmr/routing.py", line 217, in metadata_for
return self._path_metadata[pattern]
KeyError: '/users'

Router.__init__ stores the metadata of the empty route under '/users/' (normalized with original_prefix=''), but include() looks it up as '/users' (normalized with original_prefix=router.prefix). Routes with a non-empty pattern (path('/<id>', ...)) are fine.

Workaround: use an empty router prefix and write the full segment in each route (Router('', [path('/users', ...)])).

• django-modern-rest 0.15.0 (it worked in 0.13.0, before include() looked up the metadata)
• Django 5.2, Python 3.13
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

AI disclaimer: an AI assistant was used only to help write this issue.


#bug #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
September 30, 2026 566 1