Browse Source

Merge pull request #2397 from davidism/request-json

Un-deprecate Request.json
pull/2398/head
David Lord 7 years ago committed by GitHub
parent
commit
cce6e7dccc
  1. 3
      CHANGES
  2. 8
      flask/wrappers.py
  3. 26
      tests/test_deprecations.py

3
CHANGES

@ -96,6 +96,9 @@ Major release, unreleased
- ``Flask.static_path`` - use ``Flask.static_url_path`` instead.
- ``Request.module`` - use ``Request.blueprint`` instead.
- The ``request.json`` property is no longer deprecated. (`#1421`_)
.. _#1421: https://github.com/pallets/flask/issues/1421
.. _#1489: https://github.com/pallets/flask/pull/1489
.. _#1621: https://github.com/pallets/flask/pull/1621
.. _#1898: https://github.com/pallets/flask/pull/1898

8
flask/wrappers.py

@ -8,8 +8,6 @@
:copyright: (c) 2015 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
from warnings import warn
from werkzeug.exceptions import BadRequest
from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase
@ -44,13 +42,7 @@ class JSONMixin(object):
"""This will contain the parsed JSON data if the mimetype indicates
JSON (:mimetype:`application/json`, see :meth:`is_json`), otherwise it
will be ``None``.
.. deprecated:: 1.0
Use :meth:`get_json` instead.
"""
warn(DeprecationWarning(
"'json' is deprecated. Use 'get_json()' instead."
), stacklevel=2)
return self.get_json()
def _get_data_for_json(self, cache):

26
tests/test_deprecations.py

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
"""
tests.deprecations
~~~~~~~~~~~~~~~~~~
Tests deprecation support. Not used currently.
:copyright: (c) 2015 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
import flask
class TestRequestDeprecation(object):
def test_request_json(self, recwarn, app, client):
"""Request.json is deprecated"""
@app.route('/', methods=['POST'])
def index():
assert flask.request.json == {'spam': 42}
print(flask.request.json)
return 'OK'
client.post('/', data='{"spam": 42}', content_type='application/json')
recwarn.pop(DeprecationWarning)
Loading…
Cancel
Save