Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router registry is not working as expected #292

Open
mcosti opened this issue Mar 1, 2023 · 4 comments
Open

Router registry is not working as expected #292

mcosti opened this issue Mar 1, 2023 · 4 comments

Comments

@mcosti
Copy link

mcosti commented Mar 1, 2023

Hey, thanks for this nice package!
In our code we use this pattern:

from some_package.urls import some_other_router

main_router = DefaultRouter()
main_router.registry.extend(some_other_router.registry)

urlpatterns = [
    re_path(r"api/v1/", include(router.urls)),
]

The problem while using this package is that nested_router.registry does not contain the parent resource in the name, so the API will end up being
/api/v1/nameservers

instead of

/api/v1/domain/<domain_pk>/nameservers

My hack-ish solution is this one:

NESTED_ROUTERS = [
    some_other_nested_router
]

for nested_router in NESTED_ROUTERS:
    router._urls = router.urls + nested_router.urls

But I would very much prefer if I could avoid this.

Thanks!

@alanjds
Copy link
Owner

alanjds commented Mar 1, 2023

Hi, @mcosti. Thanks for reporting it as an issue.

Yeah. I agree with you that would be better to not need to add the .urls together. That would also fix the root listing of resources.

Yet I could not figure out a clean way to do it after poking around DRF sourcecode for a while.
If you get a solution for this, that would be very welcome 👍

@mcosti
Copy link
Author

mcosti commented Mar 1, 2023

Hey @alanjds . Could you maybe share what you tried and it didn't work?

Thanks

@Djones4822
Copy link

This is a desirable improvement, would love to contribute if I can. Have either of you made headway on this?

@mcosti
Copy link
Author

mcosti commented Oct 23, 2023

I personally haven't, I just used the hack above in my project

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

No branches or pull requests

3 participants