Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not treat missing payload as empty dict #7195

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest_framework/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _parse(self):
if media_type and is_form_media_type(media_type):
empty_data = QueryDict('', encoding=self._request._encoding)
else:
empty_data = {}
empty_data = None
empty_files = MultiValueDict()
return (empty_data, empty_files)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def test_standard_behaviour_determines_no_content_GET(self):
Ensure request.data returns empty QueryDict for GET request.
"""
request = Request(factory.get('/'))
assert request.data == {}
assert request.data is None

def test_standard_behaviour_determines_no_content_HEAD(self):
"""
Ensure request.data returns empty QueryDict for HEAD request.
"""
request = Request(factory.head('/'))
assert request.data == {}
assert request.data is None

def test_request_DATA_with_form_content(self):
"""
Expand Down
11 changes: 4 additions & 7 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.shortcuts import redirect
from django.test import TestCase, override_settings

from rest_framework import fields, serializers
from rest_framework import serializers
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.test import (
Expand Down Expand Up @@ -35,13 +35,10 @@ def redirect_view(request):
return redirect('/view/')


class BasicSerializer(serializers.Serializer):
flag = fields.BooleanField(default=lambda: True)


@api_view(['POST'])
def post_view(request):
serializer = BasicSerializer(data=request.data)
serializer = serializers.Serializer(data=request.data)
serializer.allow_null = True
serializer.is_valid(raise_exception=True)
return Response(serializer.validated_data)

Expand Down Expand Up @@ -198,7 +195,7 @@ def test_empty_post_uses_default_boolean_value(self):
content_type='application/json'
)
assert response.status_code == 200
assert response.data == {"flag": True}
assert response.data is None


class TestAPIRequestFactory(TestCase):
Expand Down