Skip to content

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

Closed
wants to merge 2 commits into from
Closed

fix: double namespace #8923

wants to merge 2 commits into from

Conversation

altimore
Copy link

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.

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.
Copy link
Member

@auvipy auvipy left a 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?

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

Copy link
Author

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.

Copy link
Author

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 ?

Copy link
Author

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 ?

Copy link
Member

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

Copy link
Member

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

@auvipy
Copy link
Member

auvipy commented Apr 3, 2023

if possible, can you please also check this PR #7278

@stale
Copy link

stale bot commented Jun 10, 2023

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 stale bot added the stale label Jun 10, 2023
Copy link
Member

@auvipy auvipy left a 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

@stale
Copy link

stale bot commented Aug 12, 2023

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 stale bot added the stale label Aug 12, 2023
@tomchristie
Copy link
Member

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants