Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "AssertionError: duplicate Parameters found" when I hit /swagger url

I am implementing swagger using drf-yasg for django rest framework APIs in my project.

I follow the quick start section of drf-yasg. When I hit /swagger gets AssertionError: duplicate Parameters found. Below is my code and traceback.

urls.py

from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_view = get_schema_view(
   openapi.Info(
      title="Snippets API",
      default_version='v1',
      description="Test description",
      terms_of_service="https://www.google.com/policies/terms/",
      contact=openapi.Contact(email="[email protected]"),
      license=openapi.License(name="BSD License"),
   ),
   public=True,
   permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
    url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
    # path('graphql', csrf_exempt(GraphQLObservableUnboxingView.as_view(graphiql=True, schema=schema))),
]

Traceback


```Traceback (most recent call last):
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
    raise exc
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/views.py", line 94, in get
    schema = generator.get_schema(request, self.public)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/generators.py", line 254, in get_schema
    paths, prefix = self.get_paths(endpoints, components, request, public)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/generators.py", line 412, in get_paths
    operation = self.get_operation(view, path, prefix, method, components, request)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/generators.py", line 454, in get_operation
    operation = view_inspector.get_operation(operation_keys)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/inspectors/view.py", line 36, in get_operation
    parameters = self.add_manual_parameters(parameters)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/inspectors/view.py", line 172, in add_manual_parameters
    return merge_params(parameters, manual_parameters)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/site-packages/drf_yasg/utils.py", line 282, in merge_params
    parameters = param_list_to_odict(parameters)
  File "/home/abc/development/sw_api/env_sw_api_python3.7/lib/python3.7/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

like image 329
Navjot Gwal Avatar asked Jul 03 '20 15:07

Navjot Gwal


Video Answer


1 Answers

This probably happens because one of the APIviews has duplicate filters. In my case I had search filter duplicated. It was enabled in filter_backends = [filters.SearchFilter, DjangoFilterBackend] as well as it was a field/attribute in filterset_class = CustomerFilterSet

You can try to figure out which exact view is causing the crash by commenting out urlconfs (one by one or in batches) to pin dow the source of the problem, and check filters.

like image 152
Jerry Shaw Avatar answered Sep 19 '22 22:09

Jerry Shaw