If one would use urls like these (not a good practice but possible):
url(r'^test', ExampleView1.as_view()),
url(r'^test/delete/', ExampleView2.as_view()),
Schema generation using rest_framework.schemas.get_schema_view will fail.
I've attached minimal test django project if anyone would like to reproduce the issue.
Schema should be generated as normally does.
Throws an exception:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8001/
Django Version: 1.10.3
Python Version: 2.7.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'schema_bug_test_app']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
477. response = self.handle_exception(exc)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/views.py" in handle_exception
437. self.raise_uncaught_exception(exc)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
474. response = handler(request, *args, **kwargs)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/schemas.py" in get
593. schema = generator.get_schema(request)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/schemas.py" in get_schema
242. links = self.get_links(request)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/schemas.py" in get_links
276. insert_into(links, keys, link)
File "/Users/mlubimow/Projects/test_project/env/lib/python2.7/site-packages/rest_framework/schemas.py" in insert_into
79. target[keys[-1]] = value
Exception Type: TypeError at /
Exception Value: 'Link' object does not support item assignment
Any chance you could include the traceback of that exception?
Oh, yeah, sorry for that. I've updated report.
hello @tomchristie any idea when this will be solved?
Thanks
Not yet. Been focusing on functionality for 3.6 lately.
This also happens if an url is (or maybe also ends with? did not try this one) 'list' (a natural verb enough). The reason is that insert_into (in schemas.py) is passed a keys parameter whose last element's value is 'list', which eventually conflicts with the 'list' present in the url.
It also occurs when you use drf-extensions with NestedRoutes.
From what I remember it used to worked in 3.4.
Is it possible to have this resolved in the next patch release?
This issue is caused by usage of url_path in detail_route decorator. Any chance of fix?
class MyViewSet(mixins.RetrieveModelMixin, mixins.ListModelMixin, viewsets.GenericViewSet):
...
@detail_route(
methods=['get', ],
url_name='children-list',
url_path='children(?:/(?P<child_id>[a-zA-Z0-9]+))?',
serializer_class=emg_serializers.ChildSerializer
)
def children(self, , request, parent_id=None, child_id=None):
...
You can temporary fix it in your project using a custom SchemaView with a custom SchemaGenerator: https://stackoverflow.com/a/45323639/5157209
@carltongibson is it possible to get this fixed in 3.7.0?

π
that's the idea.
I need to look into exactly what the issue is, and then the fix, but it's on the short list
I opened #5464 with test cases for this.
Can I ask all interested to review to see that your case is covered?
@mlubimow I covered your original case.
I also added the viewset case from the Stack Overflow issue. (@ola-t I wasn't entirely sure your case with children matches this 100% βΒ can you confirm?)
@everyone: Are you seeing a case that's a bit different?
I'll take PRs on https://github.com/carltongibson/django-rest-framework on the 37/schema-naming-collisions branch adding extra test cases β just copy the two examples.
Please don't be shy β if your case isn't covered it won't be fixed for v3.7!
Hey @carltongibson,
I think my case may not be covered, as I've got a problem when URL contained http method name in path (like get/post/delete etc). For example: url(r'^test/delete/', simple_fbv).
Thanks for fixing that issue! π
@mlubimow Can you then try and replicate the issue in a test case?
Why? Because this does not raise:
def test_manually_routing_with_delete(self):
patterns = [
url(r'^test', simple_fbv),
url(r'^test/delete/', simple_fbv), # !!!: Using `delete`
]
generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
schema = generator.get_schema()
That means there's info missing from your description. I'm happy to fix it, but I need the reproduce... π
(PR to my fork on 37/schema-naming-collisions branch)
@carltongibson I tried to reproduce it on your branch but I can't - I'm not sure if its because of a different way of getting the list of endpoints (as in my MVP attached to the issue endpoints are read from settings using EndpointInspector) or it has been fixed since then (when I created a ticket PIP version of DRF was 3.5.3).
Installing new version of DRF in my MVP yields another error..
@mlubimow I added a GenericAPIView based example that shows the behaviour your saw. fa87a95636af4932592b292da70189f10b4e3318
@carltongibson thanks!
Most helpful comment
Is it possible to have this resolved in the next patch release?