Deprecations

This commit is contained in:
Tom Christie 2015-07-30 15:26:42 +01:00
parent 1f55bc747b
commit c203ca4c64
7 changed files with 27 additions and 118 deletions

View File

@ -195,7 +195,8 @@ class PageNumberPagination(BasePagination):
"""
Prior to version 3.1, pagination was handled in the view, and the
attributes were set there. The attributes should now be set on
the pagination class, but the old style is still pending deprecation.
the pagination class. The old style continues to work but is deprecated
and will be fully removed in version 3.3.
"""
assert not (
getattr(view, 'pagination_serializer_class', None) or
@ -216,11 +217,11 @@ class PageNumberPagination(BasePagination):
if value is not None:
setattr(self, attr_name, value)
warnings.warn(
"The `%s` settings key is pending deprecation. "
"The `%s` settings key is deprecated. "
"Use the `%s` attribute on the pagination class instead." % (
settings_key, attr_name
),
PendingDeprecationWarning,
DeprecationWarning,
)
for (view_attr, attr_name) in (
@ -233,11 +234,11 @@ class PageNumberPagination(BasePagination):
if value is not None:
setattr(self, attr_name, value)
warnings.warn(
"The `%s` view attribute is pending deprecation. "
"The `%s` view attribute is deprecated. "
"Use the `%s` attribute on the pagination class instead." % (
view_attr, attr_name
),
PendingDeprecationWarning,
DeprecationWarning,
)
def paginate_queryset(self, queryset, request, view=None):

View File

@ -204,58 +204,12 @@ class Request(object):
"""
return self._request.GET
@property
def QUERY_PARAMS(self):
"""
Synonym for `.query_params`, for backwards compatibility.
"""
warnings.warn(
"`request.QUERY_PARAMS` is deprecated. Use `request.query_params` instead.",
DeprecationWarning,
stacklevel=1
)
return self._request.GET
@property
def data(self):
if not _hasattr(self, '_full_data'):
self._load_data_and_files()
return self._full_data
@property
def DATA(self):
"""
Parses the request body and returns the data.
Similar to usual behaviour of `request.POST`, except that it handles
arbitrary parsers, and also works on methods other than POST (eg PUT).
"""
warnings.warn(
"`request.DATA` is deprecated. Use `request.data` instead.",
DeprecationWarning,
stacklevel=1
)
if not _hasattr(self, '_data'):
self._load_data_and_files()
return self._data
@property
def FILES(self):
"""
Parses the request body and returns any files uploaded in the request.
Similar to usual behaviour of `request.FILES`, except that it handles
arbitrary parsers, and also works on methods other than POST (eg PUT).
"""
warnings.warn(
"`request.FILES` is deprecated. Use `request.data` instead.",
DeprecationWarning,
stacklevel=1
)
if not _hasattr(self, '_files'):
self._load_data_and_files()
return self._files
@property
def user(self):
"""

View File

@ -1181,44 +1181,6 @@ class ModelSerializer(Serializer):
kwargs['read_only'] = True
extra_kwargs[field_name] = kwargs
# These are all pending deprecation.
write_only_fields = getattr(self.Meta, 'write_only_fields', None)
if write_only_fields is not None:
warnings.warn(
"The `Meta.write_only_fields` option is deprecated. "
"Use `Meta.extra_kwargs={<field_name>: {'write_only': True}}` instead.",
DeprecationWarning,
stacklevel=3
)
for field_name in write_only_fields:
kwargs = extra_kwargs.get(field_name, {})
kwargs['write_only'] = True
extra_kwargs[field_name] = kwargs
view_name = getattr(self.Meta, 'view_name', None)
if view_name is not None:
warnings.warn(
"The `Meta.view_name` option is deprecated. "
"Use `Meta.extra_kwargs={'url': {'view_name': ...}}` instead.",
DeprecationWarning,
stacklevel=3
)
kwargs = extra_kwargs.get(self.url_field_name, {})
kwargs['view_name'] = view_name
extra_kwargs[self.url_field_name] = kwargs
lookup_field = getattr(self.Meta, 'lookup_field', None)
if lookup_field is not None:
warnings.warn(
"The `Meta.lookup_field` option is deprecated. "
"Use `Meta.extra_kwargs={'url': {'lookup_field': ...}}` instead.",
DeprecationWarning,
stacklevel=3
)
kwargs = extra_kwargs.get(self.url_field_name, {})
kwargs['lookup_field'] = lookup_field
extra_kwargs[self.url_field_name] = kwargs
return extra_kwargs
def get_uniqueness_extra_kwargs(self, field_names, declared_fields, extra_kwargs):

View File

@ -428,14 +428,6 @@ class APIView(View):
exception_handler = self.settings.EXCEPTION_HANDLER
if len(inspect.getargspec(exception_handler).args) == 1:
warnings.warn(
'The `exception_handler(exc)` call signature is deprecated. '
'Use `exception_handler(exc, context) instead.',
DeprecationWarning
)
response = exception_handler(exc)
else:
context = self.get_exception_handler_context()
response = exception_handler(exc, context)

View File

@ -81,7 +81,7 @@ class MockGETView(APIView):
class MockPOSTView(APIView):
def post(self, request, **kwargs):
return Response({'foo': request.DATA})
return Response({'foo': request.data})
class EmptyGETView(APIView):

View File

@ -76,37 +76,37 @@ class TestMethodOverloading(TestCase):
class TestContentParsing(TestCase):
def test_standard_behaviour_determines_no_content_GET(self):
"""
Ensure request.DATA returns empty QueryDict for GET request.
Ensure request.data returns empty QueryDict for GET request.
"""
request = Request(factory.get('/'))
self.assertEqual(request.DATA, {})
self.assertEqual(request.data, {})
def test_standard_behaviour_determines_no_content_HEAD(self):
"""
Ensure request.DATA returns empty QueryDict for HEAD request.
Ensure request.data returns empty QueryDict for HEAD request.
"""
request = Request(factory.head('/'))
self.assertEqual(request.DATA, {})
self.assertEqual(request.data, {})
def test_request_DATA_with_form_content(self):
"""
Ensure request.DATA returns content for POST request with form content.
Ensure request.data returns content for POST request with form content.
"""
data = {'qwerty': 'uiop'}
request = Request(factory.post('/', data))
request.parsers = (FormParser(), MultiPartParser())
self.assertEqual(list(request.DATA.items()), list(data.items()))
self.assertEqual(list(request.data.items()), list(data.items()))
def test_request_DATA_with_text_content(self):
"""
Ensure request.DATA returns content for POST request with
Ensure request.data returns content for POST request with
non-form content.
"""
content = six.b('qwerty')
content_type = 'text/plain'
request = Request(factory.post('/', content, content_type=content_type))
request.parsers = (PlainTextParser(),)
self.assertEqual(request.DATA, content)
self.assertEqual(request.data, content)
def test_request_POST_with_form_content(self):
"""
@ -119,27 +119,27 @@ class TestContentParsing(TestCase):
def test_standard_behaviour_determines_form_content_PUT(self):
"""
Ensure request.DATA returns content for PUT request with form content.
Ensure request.data returns content for PUT request with form content.
"""
data = {'qwerty': 'uiop'}
request = Request(factory.put('/', data))
request.parsers = (FormParser(), MultiPartParser())
self.assertEqual(list(request.DATA.items()), list(data.items()))
self.assertEqual(list(request.data.items()), list(data.items()))
def test_standard_behaviour_determines_non_form_content_PUT(self):
"""
Ensure request.DATA returns content for PUT request with
Ensure request.data returns content for PUT request with
non-form content.
"""
content = six.b('qwerty')
content_type = 'text/plain'
request = Request(factory.put('/', content, content_type=content_type))
request.parsers = (PlainTextParser(), )
self.assertEqual(request.DATA, content)
self.assertEqual(request.data, content)
def test_overloaded_behaviour_allows_content_tunnelling(self):
"""
Ensure request.DATA returns content for overloaded POST request.
Ensure request.data returns content for overloaded POST request.
"""
json_data = {'foobar': 'qwerty'}
content = json.dumps(json_data)
@ -150,7 +150,7 @@ class TestContentParsing(TestCase):
}
request = Request(factory.post('/', form_data))
request.parsers = (JSONParser(), )
self.assertEqual(request.DATA, json_data)
self.assertEqual(request.data, json_data)
def test_form_POST_unicode(self):
"""

View File

@ -25,7 +25,7 @@ class BasicView(APIView):
return Response({'method': 'GET'})
def post(self, request, *args, **kwargs):
return Response({'method': 'POST', 'data': request.DATA})
return Response({'method': 'POST', 'data': request.data})
@api_view(['GET', 'POST', 'PUT', 'PATCH'])
@ -33,11 +33,11 @@ def basic_view(request):
if request.method == 'GET':
return {'method': 'GET'}
elif request.method == 'POST':
return {'method': 'POST', 'data': request.DATA}
return {'method': 'POST', 'data': request.data}
elif request.method == 'PUT':
return {'method': 'PUT', 'data': request.DATA}
return {'method': 'PUT', 'data': request.data}
elif request.method == 'PATCH':
return {'method': 'PATCH', 'data': request.DATA}
return {'method': 'PATCH', 'data': request.data}
class ErrorView(APIView):