Merge pull request #2397 from davidism/request-json

Un-deprecate Request.json
This commit is contained in:
David Lord 2017-06-26 09:47:36 -07:00 committed by GitHub
commit cce6e7dccc
3 changed files with 3 additions and 34 deletions

View file

@ -96,6 +96,9 @@ Major release, unreleased
- ``Flask.static_path`` - use ``Flask.static_url_path`` instead. - ``Flask.static_path`` - use ``Flask.static_url_path`` instead.
- ``Request.module`` - use ``Request.blueprint`` 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 .. _#1489: https://github.com/pallets/flask/pull/1489
.. _#1621: https://github.com/pallets/flask/pull/1621 .. _#1621: https://github.com/pallets/flask/pull/1621
.. _#1898: https://github.com/pallets/flask/pull/1898 .. _#1898: https://github.com/pallets/flask/pull/1898

View file

@ -8,8 +8,6 @@
:copyright: (c) 2015 by Armin Ronacher. :copyright: (c) 2015 by Armin Ronacher.
:license: BSD, see LICENSE for more details. :license: BSD, see LICENSE for more details.
""" """
from warnings import warn
from werkzeug.exceptions import BadRequest from werkzeug.exceptions import BadRequest
from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase 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 """This will contain the parsed JSON data if the mimetype indicates
JSON (:mimetype:`application/json`, see :meth:`is_json`), otherwise it JSON (:mimetype:`application/json`, see :meth:`is_json`), otherwise it
will be ``None``. 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() return self.get_json()
def _get_data_for_json(self, cache): def _get_data_for_json(self, cache):

View file

@ -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)