-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Closed
Labels
Description
Checklist
- I have verified that that issue exists against the
master
branch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- This is not a usage question. (Those should be directed to the discussion group instead.)
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
List data makes any view / viewset crash.
I tested versions from 3.6.3 till 3.7.3 (current pypi) and master.
Steps to reproduce
Just create simple ApiView / Viewset and serializer (does not matter Serializer or ModelSerializer)
from rest_framework import generics, serializers
class TestSerializer(serializers.Serializer):
value = serializers.IntegerField()
class TestView(generics.CreateAPIView):
serializer_class = TestSerializer
def get_queryset(self):
return TestModel.objects.all()
then post JSON data (any array):
[{}]
You get stack trace:
Internal Server Error: /api/v1/test/
Traceback (most recent call last):
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_response
response = response.render()
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/django/template/response.py", line 107, in render
self.content = self.rendered_content
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/response.py", line 72, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/renderers.py", line 716, in render
context = self.get_context(data, accepted_media_type, renderer_context)
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/renderers.py", line 689, in get_context
'post_form': self.get_rendered_html_form(data, view, 'POST', request),
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/renderers.py", line 495, in get_rendered_html_form
return self.render_form_for_serializer(existing_serializer)
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/renderers.py", line 521, in render_form_for_serializer
serializer.data,
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/serializers.py", line 533, in data
ret = super(Serializer, self).data
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/serializers.py", line 266, in data
self._data = self.get_initial()
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/serializers.py", line 403, in get_initial
for field_name, field in self.fields.items()
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/serializers.py", line 404, in <listcomp>
if (field.get_value(self.initial_data) is not empty) and
File "/slowhome/ferox/Projects/ubp/myenv/lib/python3.5/site-packages/rest_framework/fields.py", line 433, in get_value
return dictionary.get(self.field_name, empty)
Expected behavior
Validation input data type?
Actual behavior
500