drf-yasg
drf-yasg copied to clipboard
"duplicate Parameters found"
i have this error : .env/lib/python3.9/site-packages/drf_yasg/utils.py", line 267, in param_list_to_odict assert len(result) == len(parameters), "duplicate Parameters found" AssertionError: duplicate Parameters found
Could you give us the full stack trace and some minimal code to reproduce the error please?
That's because you use both filter class and filter backend in the same view. I have this problem too and I don't know how to fix it!
Traceback (most recent call last):
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_respon
se
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_v
iew
return view_func(*args, **kwargs)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_e
xception
raise exc
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/views.py", line 94, in get
schema = generator.get_schema(request, self.public)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/generators.py", line 246, in get_schema
paths, prefix = self.get_paths(endpoints, components, request, public)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/generators.py", line 404, in get_paths
operation = self.get_operation(view, path, prefix, method, components, request)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/generators.py", line 446, in get_operation
operation = view_inspector.get_operation(operation_keys)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/inspectors/view.py", line 36, in get_operatio$
parameters = self.add_manual_parameters(parameters)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/inspectors/view.py", line 172, in add_manual_$arameters
return merge_params(parameters, manual_parameters)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/utils.py", line 293, in merge_params
parameters = param_list_to_odict(parameters)
File "/root/.cache/pypoetry/virtualenvs/api-N-pLUcDe-py3.9/lib/python3.9/site-packages/drf_yasg/utils.py", line 278, in param_list_to_odict
assert len(result) == len(parameters), "duplicate Parameters found"
AssertionError: duplicate Parameters found
i try drf-yasg
first time in an exist project and got this error. i don't know how to reproduce it.
the parameters
is:
[Parameter([('name', 'account_type'), ('in', 'query'), ('description', ''), ('required', False), ('type', 'string')]), Parameter([('name', 'user
name'), ('in', 'query'), ('description', ''), ('required', False), ('type', 'string')]), Parameter([('name', 'username_sha'), ('in', 'query'), (
'description', ''), ('required', False), ('type', 'string')]), Parameter([('name', 'created_at'), ('in', 'query'), ('description', ''), ('requir
ed', False), ('type', 'string')]), Parameter([('name', 'account_type'), ('in', 'query'), ('description', ''), ('required', False), ('type', 'str
ing')]), Parameter([('name', 'username'), ('in', 'query'), ('description', ''), ('required', False), ('type', 'string')]), Parameter([('name', '
username_sha'), ('in', 'query'), ('description', ''), ('required', False), ('type', 'string')]), Parameter([('name', 'created_at'), ('in', 'quer
y'), ('description', ''), ('required', False), ('type', 'string')]), Parameter([('name', 'search'), ('in', 'query'), ('description', 'A search t
erm.'), ('required', False), ('type', 'string')]), Parameter([('name', 'ordering'), ('in', 'query'), ('description', 'Which field to use when or
dering the results.'), ('required', False), ('type', 'string')]), Parameter([('name', 'page'), ('in', 'query'), ('description', 'A page number w
ithin the paginated result set.'), ('required', False), ('type', 'integer')]), Parameter([('name', 'limit'), ('in', 'query'), ('description', 'N
umber of results to return per page.'), ('required', False), ('type', 'integer')])]
the result
is:
OrderedDict([(('account_type', 'query'), Parameter([('name', 'account_type'), ('in', 'query'), ('description', ''), ('required', False), ('type'
, 'string')])), (('username', 'query'), Parameter([('name', 'username'), ('in', 'query'), ('description', ''), ('required', False), ('type', 'st
ring')])), (('username_sha', 'query'), Parameter([('name', 'username_sha'), ('in', 'query'), ('description', ''), ('required', False), ('type',
'string')])), (('created_at', 'query'), Parameter([('name', 'created_at'), ('in', 'query'), ('description', ''), ('required', False), ('type', '
string')])), (('search', 'query'), Parameter([('name', 'search'), ('in', 'query'), ('description', 'A search term.'), ('required', False), ('typ
e', 'string')])), (('ordering', 'query'), Parameter([('name', 'ordering'), ('in', 'query'), ('description', 'Which field to use when ordering th
e results.'), ('required', False), ('type', 'string')])), (('page', 'query'), Parameter([('name', 'page'), ('in', 'query'), ('description', 'A p
age number within the paginated result set.'), ('required', False), ('type', 'integer')])), (('limit', 'query'), Parameter([('name', 'limit'), (
'in', 'query'), ('description', 'Number of results to return per page.'), ('required', False), ('type', 'integer')]))])
Then, what this is? and what may cause this error and how to avoid it, thanks.
cc @JoelLefkowitz
I had this issue because i accidentally had duplicates in DEFAULT_FILTER_BACKEND
of REST_FRAMEWORK
.
Specifically:
"DEFAULT_FILTER_BACKENDS": (
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework_json_api.django_filters.DjangoFilterBackend",
),
After removing one of them it worked again.