You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have reduced the issue to the simplest possible case.
Description
If any ValidationError is raised in a view which is going to use StaticHTMLRenderer then it will cause an error resulting in an Internal-Server-Error because the base class TemplateHTMLRenderer expectes to handle with a dict while in this case it receives a list instead.
fromdjango.testimportTestCasefromrest_frameworkimportexceptionsfromrest_framework.renderersimportStaticHTMLRendererfromrest_framework.testimportURLPatternsTestCaseclassStaticHTMLRendererErrorTests(URLPatternsTestCase):
classStaticErrorView(APIView):
renderer_classes= (StaticHTMLRenderer,)
defget(self, request, **kwargs):
raiseexceptions.ValidationError('error')
urlpatterns= [path('error', StaticErrorView.as_view())]
deftest_statis_renderer_with_api_exception(self):
response=self.client.get('/error') # this line raise a TypeErrorassertresponse.status_code==400
Stacktrace
TypeError: list indices must be integers or slices, not str
failed: tests/test_renderers.py:633: in test_statis_renderer_with_api_exception
response = self.client.get('/error')
.venv/lib/python/site-packages/django/test/client.py:742: in get
response = super().get(path, data=data, secure=secure, **extra)
.venv/lib/python/site-packages/django/test/client.py:398: in get
**extra,
.venv/lib/python/site-packages/django/test/client.py:473: in generic
return self.request(**r)
.venv/lib/python/site-packages/django/test/client.py:714: in request
response = self.handler(environ)
.venv/lib/python/site-packages/django/test/client.py:145: in __call__
response = self.get_response(request)
.venv/lib/python/site-packages/django/core/handlers/base.py:130: in get_response
response = self._middleware_chain(request)
.venv/lib/python/site-packages/django/core/handlers/exception.py:49: in inner
response = response_for_exception(request, exc)
.venv/lib/python/site-packages/django/core/handlers/exception.py:114: in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
.venv/lib/python/site-packages/django/core/handlers/exception.py:47: in inner
response = get_response(request)
.venv/lib/python/site-packages/django/utils/deprecation.py:117: in __call__
response = response or self.get_response(request)
.venv/lib/python/site-packages/django/core/handlers/exception.py:49: in inner
response = response_for_exception(request, exc)
.venv/lib/python/site-packages/django/core/handlers/exception.py:114: in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
.venv/lib/python/site-packages/django/core/handlers/exception.py:47: in inner
response = get_response(request)
.venv/lib/python/site-packages/django/utils/deprecation.py:117: in __call__
response = response or self.get_response(request)
.venv/lib/python/site-packages/django/core/handlers/exception.py:49: in inner
response = response_for_exception(request, exc)
.venv/lib/python/site-packages/django/core/handlers/exception.py:114: in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
.venv/lib/python/site-packages/django/core/handlers/exception.py:47: in inner
response = get_response(request)
.venv/lib/python/site-packages/django/utils/deprecation.py:117: in __call__
response = response or self.get_response(request)
.venv/lib/python/site-packages/django/core/handlers/exception.py:49: in inner
response = response_for_exception(request, exc)
.venv/lib/python/site-packages/django/core/handlers/exception.py:114: in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
.venv/lib/python/site-packages/django/core/handlers/exception.py:47: in inner
response = get_response(request)
.venv/lib/python/site-packages/django/utils/deprecation.py:117: in __call__
response = response or self.get_response(request)
.venv/lib/python/site-packages/django/core/handlers/exception.py:49: in inner
response = response_for_exception(request, exc)
.venv/lib/python/site-packages/django/core/handlers/exception.py:114: in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
.venv/lib/python/site-packages/django/core/handlers/exception.py:47: in inner
response = get_response(request)
.venv/lib/python/site-packages/django/core/handlers/base.py:204: in _get_response
response = response.render()
.venv/lib/python/site-packages/django/template/response.py:105: in render
self.content = self.rendered_content
rest_framework/response.py:74: in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
rest_framework/renderers.py:232: in render
context = self.get_template_context(data, renderer_context)
rest_framework/renderers.py:174: in get_template_context
data['status_code'] = response.status_code
E TypeError: list indices must be integers or slices, not str
The text was updated successfully, but these errors were encountered:
Checklist
Description
If any
ValidationError
is raised in a view which is going to useStaticHTMLRenderer
then it will cause an error resulting in an Internal-Server-Error because the base classTemplateHTMLRenderer
expectes to handle with adict
while in this case it receives alist
instead.django-rest-framework/rest_framework/renderers.py
Lines 171 to 175 in 0f39e01
Code sample
Stacktrace
TypeError: list indices must be integers or slices, not str
The text was updated successfully, but these errors were encountered: