Skip to content
Myr

Ignore cache on request.get_json(cache=False) call (#2089)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Test cache argument of Request.get_json * Ignore cache on request.get_json(cache=False) call Removes usage of `_cached_json` property when `get_json` is called with disabled cache argument. (closes #2087)

authored by Jiri Kuncar · committed by Markus Unterwaditzer · parent 0e79aba · Browse files · 2 files+10 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−1 removed

  • tests:+8 added−0 removed
  • other:+2 added−1 removed

2 files+10 added−1 removed

modified:flask/wrappers.py+2 added-1 removed
135 unmodified lines
136 :param cache: if set to ``True`` the parsed JSON data is remembered137 on the request.138 """139 rv = getattr(self, '_cached_json', _missing)140 # We return cached JSON only when the cache is enabled.140 if rv is not _missing:141 if cache and rv is not _missing:142 return rv143144 if not (force or self.is_json):145 return None
60 unmodified lines
modified:tests/test_helpers.py+8 added
33 unmodified lines
343536class TestJSON(object):3738 def test_ignore_cached_json(self):39 app = flask.Flask(__name__)40 with app.test_request_context('/', method='POST', data='malformed',41 content_type='application/json'):42 assert flask.request.get_json(silent=True, cache=True) is None43 with pytest.raises(BadRequest):44 flask.request.get_json(silent=False, cache=False)4546 def test_post_empty_json_adds_exception_to_response_content_in_debug(self):47 app = flask.Flask(__name__)48 app.config['DEBUG'] = True49 @app.route('/json', methods=['POST'])
838 unmodified lines