-
-
Notifications
You must be signed in to change notification settings - Fork 7k
fix: double namespace #8923
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
fix: double namespace #8923
Conversation
When using namespaces on my apps and django generic relation project 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 ``` so i just added a test in def get_versioned_viewname(self, viewname, request): to not change the view name i there is already a namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add test case to verify this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, you can do in one line
return f"{request.version}:{viewname}" if ":" not in viewname else viewname
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from list comprehension, I'm usually not found of one liners in python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, can you give me an example of what you want me to add ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, can you give me an example of what you want me to add ?
i mean where should i add test case and in which way ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can check for existing tests https://github.com/encode/django-rest-framework/blob/master/tests/test_versioning.py and then add your relevant additional unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can check for existing tests https://github.com/encode/django-rest-framework/blob/master/tests/test_versioning.py and then add your relevant additional unit tests
if possible, can you please also check this PR #7278 |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see unit test coverage for this change
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. |
https://docs.djangoproject.com/en/5.0/topics/http/urls/#url-namespaces
|
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
and this is what i get in the console
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.