-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Fix format_suffix_patterns behavior with Django 2 path() routes #5691
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
Conversation
I think this is a bit hard to fix properly. As it is now, def format_suffix_patterns(urlpatterns, suffix_required=False, allowed=None):
... As far as I can tell, the only way to enforce that in Django 2 path would be to register a custom path converter for all combinations of Note: generating regex patterns from route patterns is not an option, because the new converters actually transform their captured value, i.e. a view registered at |
Declaring the converter class within a function, rather than at the top-level of a module would be perfectly reasonable. We could just call the class |
A reasonable approach to fixing this would be to start with the simpler, but not-quite-there case of just capturing suffixes against the If you wanted to tackle getting the PR to that point, I'd be very happy to then look at taking it the rest of the way over the line. |
* needs more tests * maybe needs some refactoring
return value.strip('./') | ||
|
||
def to_url(self, value): | ||
return '.' + value + '/' |
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.
Perfect approach, yup.
rest_framework/urlpatterns.py
Outdated
ret.append(url(regex, view, kwargs, name)) | ||
|
||
# we create a new RegexPattern url; if the original pattern | ||
# was a RoutePattern we need to preserve its converters |
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.
Ignore this comment, forgot to remove from an earlier idea
@axnsan12 Looking good! Last commit is "WIP" - what's left to do here? |
I am writing some tests now, found a bug related to the trailing slash one. I'm trying to figure out how it's implemented for regex, because for the path case, my implementation generates a path which matches the first, not the second.
EDIT: found it |
I think it should be about good to go EDIT: however, since #5672 did not provide any concrete details about the errors encountered, I have no idea if they were fixed; this definitely did fix the path converter issue I outlined in the first comment, though. |
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.
@axnsan12 This looks great. Thanks for the quick input.
(If there are edge-cases left we'll take them as reported.)
Nice to get this in the release! 💃🏼
Thanks for such detailed analysis @axnsan12. Being a beginnner with django-rest-framework didnt let me dive into the depth of such an issue. Always good to know new stuff. |
…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
* Update version for 3.7.4 Release * Add release notes to 01587b9 * Django 2.0 is now final. * Add trove classifer for Django 2.0 * Finalise release notes for v3.7.4 * Set release date: December 20, 2017 * Update Transifex * Add release note for encode#5691 * Move Issue links to bottom
Broken urls are generated by
format_suffix_patterns
when usingurlpatterns
specified with the newpath()
routes added in Django 2.Closes #5672