axnsan12 / drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
https://drf-yasg.readthedocs.io/en/stable/
Other
3.43k stars 439 forks source link

AttributeError: 'list' object has no attribute 'model' #576

Closed cromulent-coder closed 4 years ago

cromulent-coder commented 4 years ago
schema_view = get_schema_view(
    openapi.Info(
        title="NutriPal API's",
        default_version='v1',
        description="Test description",
        terms_of_service="https://www.google.com/policies/terms/",
        contact=openapi.Contact(email="rohit@nutripal.biz"),
        license=openapi.License(name="BSD License"),
    ),
    validators=['ssv'],
    public=True,
    permission_classes=(permissions.AllowAny,),
)

url(r'^swagger/$', schema_view.with_ui('swagger', `cache_timeout=0))

On Accessing localhost:8000/swagger Getting Error

Traceback (most recent call last): File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "c:\users\rohit\appdata\local\programs\python\python36\Lib\contextlib.py", line 52, in inner return func(*args, *kwds) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view return view_func(args, kwargs) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django\views\generic\base.py", line 71, in view return self.dispatch(request, *args, *kwargs) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\rest_framework\views.py", line 505, in dispatch response = self.handle_exception(exc) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\rest_framework\views.py", line 465, in handle_exception self.raise_uncaught_exception(exc) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception raise exc File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\rest_framework\views.py", line 502, in dispatch response = handler(request, args, kwargs) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\views.py", line 94, in get schema = generator.get_schema(request, self.public) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\generators.py", line 254, in get_schema paths, prefix = self.get_paths(endpoints, components, request, public) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\generators.py", line 412, in get_paths operation = self.get_operation(view, path, prefix, method, components, request) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\generators.py", line 454, in get_operation operation = view_inspector.get_operation(operation_keys) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\inspectors\view.py", line 33, in get_operation query = self.get_query_parameters() File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\inspectors\view.py", line 291, in get_query_parameters natural_parameters = self.get_filter_parameters() + self.get_pagination_parameters() File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\inspectors\base.py", line 416, in get_filter_parameters fields += self.probe_inspectors(self.filter_inspectors, 'get_filter_parameters', filter_backend()) or [] File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\inspectors\base.py", line 118, in probe_inspectors result = method(obj, kwargs) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\drf_yasg\inspectors\query.py", line 26, in get_filter_parameters fields = filter_backend.get_schema_fields(self.view) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django_filters\rest_framework\backends.py", line 131, in get_schema_fields filterset_class = self.get_filterset_class(view, queryset) File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django_filters\rest_framework\backends.py", line 73, in get_filterset_class class AutoFilterSet(self.filterset_base): File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django_filters\rest_framework\backends.py", line 74, in AutoFilterSet class Meta(MetaBase): File "C:\Users\ROHIT.virtualenvs\nutripal-uAVg5GiP\lib\site-packages\django_filters\rest_framework\backends.py", line 75, in Meta model = queryset.model AttributeError: 'list' object has no attribute 'model'

Headmaster11 commented 4 years ago

Got the same error. Any info/update on it?

Headmaster11 commented 4 years ago

I found, the problem was that in one View I returned empty list instead of empty Queryset

axnsan12 commented 4 years ago

Makes sense. The original stack trace even points to this, and is deep into DRF code. Closing