django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

fix: double namespace

Open altimore opened this issue 2 years ago • 3 comments

Description

When using namespaces on my apps and rest framework generic relation https://github.com/LilyFoote/rest-framework-generic-relations project with the i get a double name space : in relations.py i added this print statement on the line 383 before the matching viewname test

print(
    f"Comparing '{match.view_name}' to '{expected_viewname}', self.view_name = {self.view_name} "
)

and this is what i get in the console

Comparing invoices:invoice-detail to reminders:invoices:invoice-detail, self.view_name = invoices:invoice-detail 

solution

so i just added a test in def get_versioned_viewname(self, viewname, request): to not change the view name if there is already a namespace.

alternative

we could take out the existing namespace to replace it with the required one or we could make a more precise error message to explain how to bypass this behavior.

My use case required the reminder namespace to not be added.

altimore avatar Mar 30 '23 09:03 altimore

if possible, can you please also check this PR https://github.com/encode/django-rest-framework/pull/7278

auvipy avatar Apr 03 '23 07:04 auvipy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 10 '23 17:06 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '23 12:08 stale[bot]

https://docs.djangoproject.com/en/5.0/topics/http/urls/#url-namespaces

Namespaces can also be nested. The named URL 'sports:polls:index' would look for ...

lovelydinosaur avatar Mar 22 '24 18:03 lovelydinosaur