You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that 3.15 is not part of the the supported versions of DRF yet but I thought this would be useful to bring up. This is my first time doing something like this so please let me know if it's off base.
Ran into this when I was looking to use a custom url converter and attempting to apply the converter to nested URLs using NestedSimpleRouter
When use_regex_path=False on SimpleRouter it will strip the regex ^ and $ characters from the router routes causing the following line to not properly pre-pend the parent_prefix to the route.
DRF 3.15 regex strip:
if use_regex_path:
self._base_pattern = '(?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})'
self._default_value_pattern = '[^/.]+'
self._url_conf = re_path
else:
self._base_pattern = '<{lookup_value}:{lookup_prefix}{lookup_url_kwarg}>'
self._default_value_pattern = 'str'
self._url_conf = path
# remove regex characters from routes
_routes = []
for route in self.routes:
url_param = route.url
if url_param[0] == '^':
url_param = url_param[1:]
if url_param[-1] == '$':
url_param = url_param[:-1]
NestedMixin's route replacement for regex ^ character route_contents['url'] = route.url.replace('^', '^' + escaped_parent_regex)
The '^' does not exist in this case and the router fails silently not pre-pending any parent to the route.
Example to reproduce is to use DRF 3.15 and set up the following urls.py:
for route in self.routes:
route_contents = route._asdict()
# This will get passed through .format in a little bit, so we need
# to escape it
escaped_parent_regex = self.parent_regex.replace('{', '{{').replace('}', '}}')
if self.use_regex_path:
route_contents['url'] = route.url.replace('^', '^' + escaped_parent_regex)
else:
route_contents['url'] = escaped_parent_regex + route_contents['url']
nested_routes.append(type(route)(**route_contents))
The text was updated successfully, but these errors were encountered:
I know that 3.15 is not part of the the supported versions of DRF yet but I thought this would be useful to bring up. This is my first time doing something like this so please let me know if it's off base.
Ran into this when I was looking to use a custom url converter and attempting to apply the converter to nested URLs using NestedSimpleRouter
When use_regex_path=False on SimpleRouter it will strip the regex ^ and $ characters from the router routes causing the following line to not properly pre-pend the parent_prefix to the route.
DRF 3.15 regex strip:
NestedMixin's route replacement for regex ^ character
route_contents['url'] = route.url.replace('^', '^' + escaped_parent_regex)
The '^' does not exist in this case and the router fails silently not pre-pending any parent to the route.
Example to reproduce is to use DRF 3.15 and set up the following urls.py:
I made quick and dirty fix locally by doing something like below:
The text was updated successfully, but these errors were encountered: