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

format_suffix_pattern not working with path() in django 2.0 #5672

Closed
5 of 6 tasks
mr-skyaakash opened this issue Dec 14, 2017 · 2 comments · Fixed by #5691
Closed
5 of 6 tasks

format_suffix_pattern not working with path() in django 2.0 #5672

mr-skyaakash opened this issue Dec 14, 2017 · 2 comments · Fixed by #5691
Labels

Comments

@mr-skyaakash
Copy link

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

Expected behavior

when using format_suffix_patterns() from the rest_framwork.urlpatterns class, it should format the url pattern for url() from django.conf.urls as well as the newly introduced path() from django.urls

Actual behavior

getting an error when using path() in urlpatterns[], and then formatting it using the format_suffix_patterns() method

@xordoquy
Copy link
Collaborator

Next step on that issue would be to write a failing test case.

axnsan12 added a commit to axnsan12/drf-yasg that referenced this issue Dec 18, 2017
In Django 2, routes defines via urls.path are aggresively escaped when converted into regex.

This is a naive fix which unescapes all characters outside capture groups, but in the context of OpenAPI is okay because regular expressions inside paths are not supported anyway.

This issue affects django-rest-framework as well, as outlined in encode/django-rest-framework#5672, encode/django-rest-framework#5675.
@adjordan
Copy link

I am having the same issue with the following urls.py file:

from django.urls import path, re_path
from rest_framework.urlpatterns import format_suffix_patterns
from snippets import views

urlpatterns = [
    path('snippets/', views.snippet_list),
    re_path('snippets/(?P<pk>[0-9]+)/', views.snippet_detail)
]

urlpatterns = format_suffix_patterns(urlpatterns)

axnsan12 added a commit to axnsan12/django-rest-framework that referenced this issue Dec 20, 2017
axnsan12 added a commit to axnsan12/django-rest-framework that referenced this issue Dec 20, 2017
carltongibson pushed a commit that referenced this issue Dec 20, 2017
* Add failing test for #5672

* Add get_original_route to complement get_regex_pattern

* [WIP] Fix path handling

* needs more tests
* maybe needs some refactoring

* Add django 2 variant for all tests and fix trailing slash bug

* Add more combinations to mixed path test
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
…de#5691)

* Add failing test for encode#5672

* Add get_original_route to complement get_regex_pattern

* [WIP] Fix path handling

* needs more tests
* maybe needs some refactoring

* Add django 2 variant for all tests and fix trailing slash bug

* Add more combinations to mixed path test
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 a pull request may close this issue.

4 participants