Removed request.REQUEST per deprecation timeline; refs #18659.

This commit is contained in:
Tim Graham 2014-11-18 11:57:05 -05:00
parent 61ad1ea92b
commit 75f107b884
6 changed files with 6 additions and 74 deletions

View File

@ -6,15 +6,12 @@ import logging
import sys import sys
from io import BytesIO from io import BytesIO
from threading import Lock from threading import Lock
import warnings
from django import http from django import http
from django.conf import settings from django.conf import settings
from django.core import signals from django.core import signals
from django.core.handlers import base from django.core.handlers import base
from django.core.urlresolvers import set_script_prefix from django.core.urlresolvers import set_script_prefix
from django.utils import datastructures
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_str, force_text from django.utils.encoding import force_str, force_text
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils import six from django.utils import six
@ -121,13 +118,6 @@ class WSGIRequest(http.HttpRequest):
def _get_scheme(self): def _get_scheme(self):
return self.environ.get('wsgi.url_scheme') return self.environ.get('wsgi.url_scheme')
def _get_request(self):
warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or '
'`request.POST` instead.', RemovedInDjango19Warning, 2)
if not hasattr(self, '_request'):
self._request = datastructures.MergeDict(self.POST, self.GET)
return self._request
@cached_property @cached_property
def GET(self): def GET(self):
# The WSGI spec says 'QUERY_STRING' may be absent. # The WSGI spec says 'QUERY_STRING' may be absent.
@ -154,7 +144,6 @@ class WSGIRequest(http.HttpRequest):
POST = property(_get_post, _set_post) POST = property(_get_post, _set_post)
FILES = property(_get_files) FILES = property(_get_files)
REQUEST = property(_get_request)
class WSGIHandler(base.BaseHandler): class WSGIHandler(base.BaseHandler):

View File

@ -108,21 +108,6 @@ All attributes should be considered read-only, unless stated otherwise below.
Note: ``POST`` does *not* include file-upload information. See ``FILES``. Note: ``POST`` does *not* include file-upload information. See ``FILES``.
.. attribute:: HttpRequest.REQUEST
.. deprecated:: 1.7
Use the more explicit ``GET`` and ``POST`` instead.
For convenience, a dictionary-like object that searches ``POST`` first,
then ``GET``. Inspired by PHP's ``$_REQUEST``.
For example, if ``GET = {"name": "john"}`` and ``POST = {"age": '34'}``,
``REQUEST["name"]`` would be ``"john"``, and ``REQUEST["age"]`` would be
``"34"``.
It's strongly suggested that you use ``GET`` and ``POST`` instead of
``REQUEST``, because the former are more explicit.
.. attribute:: HttpRequest.COOKIES .. attribute:: HttpRequest.COOKIES
A standard Python dictionary containing all cookies. Keys and values are A standard Python dictionary containing all cookies. Keys and values are

View File

@ -130,12 +130,11 @@ view; it'll apply response middleware to that
.. note:: .. note::
Accessing :attr:`request.POST <django.http.HttpRequest.POST>` or Accessing :attr:`request.POST <django.http.HttpRequest.POST>` inside
:attr:`request.REQUEST <django.http.HttpRequest.REQUEST>` inside middleware middleware from ``process_request`` or ``process_view`` will prevent any
from ``process_request`` or ``process_view`` will prevent any view running view running after the middleware from being able to :ref:`modify the
after the middleware from being able to :ref:`modify the upload handlers upload handlers for the request <modifying_upload_handlers_on_the_fly>`,
for the request <modifying_upload_handlers_on_the_fly>`, and should and should normally be avoided.
normally be avoided.
The :class:`~django.middleware.csrf.CsrfViewMiddleware` class can be The :class:`~django.middleware.csrf.CsrfViewMiddleware` class can be
considered an exception, as it provides the considered an exception, as it provides the

View File

@ -4,7 +4,7 @@ import os
import unittest import unittest
import warnings import warnings
from django.test import SimpleTestCase, RequestFactory, override_settings from django.test import SimpleTestCase, override_settings
from django.test.utils import reset_warning_registry from django.test.utils import reset_warning_registry
from django.utils import six, translation from django.utils import six, translation
from django.utils.deprecation import RenameMethodsBase from django.utils.deprecation import RenameMethodsBase
@ -175,26 +175,6 @@ class RenameMethodsTests(SimpleTestCase):
]) ])
class DeprecatingRequestMergeDictTest(SimpleTestCase):
def test_deprecated_request(self):
"""
Ensure the correct warning is raised when WSGIRequest.REQUEST is
accessed.
"""
reset_warning_registry()
with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter('always')
request = RequestFactory().get('/')
request.REQUEST # evaluate
msgs = [str(warning.message) for warning in recorded]
self.assertEqual(msgs, [
'`request.REQUEST` is deprecated, use `request.GET` or '
'`request.POST` instead.',
'`MergeDict` is deprecated, use `dict.update()` instead.',
])
@override_settings(USE_I18N=True) @override_settings(USE_I18N=True)
class DeprecatedChineseLanguageCodes(SimpleTestCase): class DeprecatedChineseLanguageCodes(SimpleTestCase):
def test_deprecation_warning(self): def test_deprecation_warning(self):

View File

@ -953,14 +953,12 @@ class zzUrlconfSubstitutionTests(TestCase):
class ContextTests(TestCase): class ContextTests(TestCase):
fixtures = ['testdata'] fixtures = ['testdata']
@ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated
def test_single_context(self): def test_single_context(self):
"Context variables can be retrieved from a single context" "Context variables can be retrieved from a single context"
response = self.client.get("/request_data/", data={'foo': 'whiz'}) response = self.client.get("/request_data/", data={'foo': 'whiz'})
self.assertEqual(response.context.__class__, Context) self.assertEqual(response.context.__class__, Context)
self.assertIn('get-foo', response.context) self.assertIn('get-foo', response.context)
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['data'], 'sausage') self.assertEqual(response.context['data'], 'sausage')
try: try:
@ -969,7 +967,6 @@ class ContextTests(TestCase):
except KeyError as e: except KeyError as e:
self.assertEqual(e.args[0], 'does-not-exist') self.assertEqual(e.args[0], 'does-not-exist')
@ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated
def test_inherited_context(self): def test_inherited_context(self):
"Context variables can be retrieved from a list of contexts" "Context variables can be retrieved from a list of contexts"
response = self.client.get("/request_data_extended/", data={'foo': 'whiz'}) response = self.client.get("/request_data_extended/", data={'foo': 'whiz'})
@ -977,7 +974,6 @@ class ContextTests(TestCase):
self.assertEqual(len(response.context), 2) self.assertEqual(len(response.context), 2)
self.assertIn('get-foo', response.context) self.assertIn('get-foo', response.context)
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['data'], 'bacon') self.assertEqual(response.context['data'], 'bacon')
try: try:
@ -1252,7 +1248,6 @@ class RequestMethodStringDataTests(TestCase):
@override_settings(ROOT_URLCONF='test_client_regress.urls',) @override_settings(ROOT_URLCONF='test_client_regress.urls',)
class QueryStringTests(TestCase): class QueryStringTests(TestCase):
@ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated
def test_get_like_requests(self): def test_get_like_requests(self):
# See: https://code.djangoproject.com/ticket/10571. # See: https://code.djangoproject.com/ticket/10571.
for method_name in ('get', 'head'): for method_name in ('get', 'head'):
@ -1260,25 +1255,19 @@ class QueryStringTests(TestCase):
method = getattr(self.client, method_name) method = getattr(self.client, method_name)
response = method("/request_data/", data={'foo': 'whiz'}) response = method("/request_data/", data={'foo': 'whiz'})
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz')
# A GET-like request can pass a query string as part of the URL # A GET-like request can pass a query string as part of the URL
response = method("/request_data/?foo=whiz") response = method("/request_data/?foo=whiz")
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz')
# Data provided in the URL to a GET-like request is overridden by actual form data # Data provided in the URL to a GET-like request is overridden by actual form data
response = method("/request_data/?foo=whiz", data={'foo': 'bang'}) response = method("/request_data/?foo=whiz", data={'foo': 'bang'})
self.assertEqual(response.context['get-foo'], 'bang') self.assertEqual(response.context['get-foo'], 'bang')
self.assertEqual(response.context['request-foo'], 'bang')
response = method("/request_data/?foo=whiz", data={'bar': 'bang'}) response = method("/request_data/?foo=whiz", data={'bar': 'bang'})
self.assertEqual(response.context['get-foo'], None) self.assertEqual(response.context['get-foo'], None)
self.assertEqual(response.context['get-bar'], 'bang') self.assertEqual(response.context['get-bar'], 'bang')
self.assertEqual(response.context['request-foo'], None)
self.assertEqual(response.context['request-bar'], 'bang')
@ignore_warnings(category=RemovedInDjango19Warning) # `request.REQUEST` is deprecated
def test_post_like_requests(self): def test_post_like_requests(self):
# A POST-like request can pass a query string as data # A POST-like request can pass a query string as data
response = self.client.post("/request_data/", data={'foo': 'whiz'}) response = self.client.post("/request_data/", data={'foo': 'whiz'})
@ -1289,21 +1278,17 @@ class QueryStringTests(TestCase):
response = self.client.post("/request_data/?foo=whiz") response = self.client.post("/request_data/?foo=whiz")
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['post-foo'], None) self.assertEqual(response.context['post-foo'], None)
self.assertEqual(response.context['request-foo'], 'whiz')
# POST data provided in the URL augments actual form data # POST data provided in the URL augments actual form data
response = self.client.post("/request_data/?foo=whiz", data={'foo': 'bang'}) response = self.client.post("/request_data/?foo=whiz", data={'foo': 'bang'})
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['post-foo'], 'bang') self.assertEqual(response.context['post-foo'], 'bang')
self.assertEqual(response.context['request-foo'], 'bang')
response = self.client.post("/request_data/?foo=whiz", data={'bar': 'bang'}) response = self.client.post("/request_data/?foo=whiz", data={'bar': 'bang'})
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['get-bar'], None) self.assertEqual(response.context['get-bar'], None)
self.assertEqual(response.context['post-foo'], None) self.assertEqual(response.context['post-foo'], None)
self.assertEqual(response.context['post-bar'], 'bang') self.assertEqual(response.context['post-bar'], 'bang')
self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['request-bar'], 'bang')
@override_settings(ROOT_URLCONF='test_client_regress.urls') @override_settings(ROOT_URLCONF='test_client_regress.urls')

View File

@ -38,17 +38,11 @@ get_view = login_required(get_view)
def request_data(request, template='base.html', data='sausage'): def request_data(request, template='base.html', data='sausage'):
"A simple view that returns the request data in the context" "A simple view that returns the request data in the context"
request_foo = request.REQUEST.get('foo')
request_bar = request.REQUEST.get('bar')
return render_to_response(template, { return render_to_response(template, {
'get-foo': request.GET.get('foo'), 'get-foo': request.GET.get('foo'),
'get-bar': request.GET.get('bar'), 'get-bar': request.GET.get('bar'),
'post-foo': request.POST.get('foo'), 'post-foo': request.POST.get('foo'),
'post-bar': request.POST.get('bar'), 'post-bar': request.POST.get('bar'),
'request-foo': request_foo,
'request-bar': request_bar,
'data': data, 'data': data,
}) })