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

dot character excluded from viewset lookup_field url conf #2033

Closed
macropin opened this issue Nov 6, 2014 · 4 comments
Closed

dot character excluded from viewset lookup_field url conf #2033

macropin opened this issue Nov 6, 2014 · 4 comments

Comments

@macropin
Copy link

macropin commented Nov 6, 2014

Somewhere between djangorestframework==2.3.13 and djangorestframework==2.4.4 the generated url conf for a ModelViewSet has changed to exclude '.' (period / dot) character. This means that your custom lookup_field cannot be a domain name, or some other string that includes this character.

Given a view set such as:

class ZoneViewSet(viewsets.ModelViewSet):
    lookup_field = 'domain__name'

The following urls are generated (djangorestframework==2.3.13):

^api/ ^v1/ ^zones/(?P<domain__name>[^/]+)/$ [name='zone-detail']
^api/ ^v1/ ^zones/(?P<domain__name>[^/]+)/\.(?P<format>[a-z0-9]+)$ [name='zone-detail']

And now with djangorestframework==2.4.4:

^api/ ^v1/ ^zones//$ [name='zone-detail']
^api/ ^v1/ ^zones/(?P<domain__name>[^/.]+)/\.(?P<format>[a-z0-9]+)$ [name='zone-detail']

The [^] specifies an exclusion set, so [^/] excludes all forward slashes, whilst [^/.]excludes forward slashes and period (dot) characters.

I believe there is no reason to restrict periods in URIs and this change should be reverted.

@macropin
Copy link
Author

macropin commented Nov 6, 2014

And here's the commit that broke this previous functionality 3cd15fb. The commit log shows that you're aware of the issue. I presume you don't intend to change it, so I'll close this issue.

Anyone who finds this be aware that in order to allow periods in urlconf generated by the default router, you need to add lookup_value_regex = '[^/]+' to your viewset.

@macropin macropin closed this as completed Nov 6, 2014
@trollfred
Copy link

I wonder why dot was excluded in the first place...

@xordoquy
Copy link
Collaborator

xordoquy commented Feb 28, 2018

Iirc dots interfer with the ability to add extension content type within urls - ie /myendpoint.json

@VictorCoCo
Copy link

And here's the commit that broke this previous functionality 3cd15fb. The commit log shows that you're aware of the issue. I presume you don't intend to change it, so I'll close this issue.

Anyone who finds this be aware that in order to allow periods in urlconf generated by the default router, you need to add lookup_value_regex = '[^/]+' to your viewset.

Thank you very very much!

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

4 participants