Open bradydean opened 9 months ago
I found an instance of this error now, same exception, but different traceback
Traceback (most recent call last):
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/asgiref/sync.py", line 534, in thread_handler
raise exc_info[1]
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/asgiref/sync.py", line 534, in thread_handler
raise exc_info[1]
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/asgiref/sync.py", line 479, in __call__
ret: _R = await loop.run_in_executor(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/asgiref/current_thread_executor.py", line 40, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/asgiref/sync.py", line 538, in thread_handler
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/django/views/decorators/cache.py", line 54, in _view_wrapper
response = viewfunc(request, *args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/views.py", line 84, in get
return self._get_schema_response(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/views.py", line 92, in _get_schema_response
data=generator.get_schema(request=request, public=self.serve_public),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/generators.py", line 281, in get_schema
paths=self.parse(request, public),
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/generators.py", line 252, in parse
operation = view.schema.get_operation(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/utils.py", line 424, in get_operation
return super().get_operation(path, path_regex, path_prefix, method, registry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/openapi.py", line 111, in get_operation
operation['responses'] = self._get_response_bodies()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/openapi.py", line 1367, in _get_response_bodies
return {'200': self._get_response_for_code(response_serializers, '200', direction=direction)}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/openapi.py", line 1444, in _get_response_for_code
self._is_list_view(serializer)
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/drf_spectacular/openapi.py", line 145, in _is_list_view
if hasattr(self.view, 'action'):
^^^^^^^^^
File "/home/app/.cache/pypoetry/virtualenvs/recovery-platform-BwZRr09X-py3.12/lib/python3.12/site-packages/rest_framework/schemas/inspectors.py", line 58, in view
assert self._view is not None, (
AssertionError: Schema generation REQUIRES a view instance. (Hint: you accessed `schema` from the view class rather than an instance.)
Hey @bradydean,
can you reproduce this issue or is probabilistic again? I am still confused how this can happen for you. This is a very basic assumption failure that should never be seen by a user.
Unfortunately I cannot reproduce it, it is probabilistic. It has happened only 6 times in the last week out of ~5000 /openapi
requests.
It definitely seems to be an issue with concurrent requests. I ran a stress test on /openapi
with locust with 10 users, 1 user/s, for 1 minute and out of 268 requests, 60 failed.
I'm seeing the same errors I've already reported, but also a new one.
With the stress test I can also reproduce it locally now, if there are any steps you want me to take to debug on my end let me know @tfranzel
I would like to debug this as close to your setup as possible. please, if possible, state as much context as possible, e.g.
I think it has to be somehow related to your concrete setup, because otherwise this should have been raised way more often, given the now widespread usage of drf-spectacular.
fedora:39
containerAlso, I just ran the stress test using gunicorn wsgi and had no errors. Maybe it's related to daphne asgi?
Thanks @bradydean for the detailed info. I will try to reproduce this over the holidays and will get back to you.
Maybe it's related to daphne asgi?
possibly...
Generally, my setups are very close to yours and I never encountered that problem. Also, daphne has never failed me like that. So in theory nothing wrong with your setup.
Thanks for the help @tfranzel
I just tried gunicorn+uvicorn worker class and the errors appear again. Seems something is up with asgi. It works fine with the gevent worker class.
Describe the bug I have a /openapi endpoint, and occasionally the API fails with this exception. This happens a few times a day, but most of the time the spec generates successfully.
To Reproduce Cannot be reproduced locally, I just have production logs of it happening.
Expected behavior API spec generates successfully every time