Use app_ctx instead of request_ctx to access the app
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Adam Byrtek · committed by Markus Unterwaditzer · parent f0d3b71 · Browse files · 1 file·+13 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+13 added−20 removed
- other:+13 added−20 removed
Provenance
- Commit
1df2788- Tree
489acfa- Author
Adam Byrtek <adambyrtek@gmail.com>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
f0d3b71
1 file changed+13 added−20 removed
modified:flask/wrappers.py+13 added-20 removed
11 unmodified lines12 from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase13 from werkzeug.exceptions import BadRequest14 15 from . import json16-from .globals import _request_ctx_stack16+from .globals import _app_ctx_stack17 18 _missing = object()19 20 79 unmodified lines100 def on_json_loading_failed(self, e):101 """Called if decoding of the JSON data failed. The return value of102 this method is used by :meth:`get_json` when an error occurred. The103 default implementation just raises a :class:`BadRequest` exception.104+105+ .. versionchanged:: 0.10106+ Removed buggy previous behavior of generating a random JSON107+ response. If you want that behavior back you can trivially108+ add it by subclassing.109+110+ .. versionadded:: 0.8111 """112+ ctx = _app_ctx_stack.top113+ if ctx is not None and ctx.app.debug:114+ raise BadRequest('Failed to decode JSON object: {0}'.format(e))115 raise BadRequest()116 117 118 class Request(RequestBase, JSONMixin):32 unmodified lines151 152 @property153 def max_content_length(self):154 """Read-only view of the ``MAX_CONTENT_LENGTH`` config key."""145- ctx = _request_ctx_stack.top155+ ctx = _app_ctx_stack.top156 if ctx is not None:157 return ctx.app.config['MAX_CONTENT_LENGTH']158 159 @property24 unmodified lines184 """The name of the current blueprint"""185 if self.url_rule and '.' in self.url_rule.endpoint:186 return self.url_rule.endpoint.rsplit('.', 1)[0]187 178- def on_json_loading_failed(self, e):179- """Called if decoding of the JSON data failed. The return value of180- this method is used by :meth:`get_json` when an error occurred. The181- default implementation just raises a :class:`BadRequest` exception.182-183- .. versionchanged:: 0.10184- Removed buggy previous behavior of generating a random JSON185- response. If you want that behavior back you can trivially186- add it by subclassing.187-188- .. versionadded:: 0.8189- """190- ctx = _request_ctx_stack.top191- if ctx is not None and ctx.app.config.get('DEBUG', False):192- raise BadRequest('Failed to decode JSON object: {0}'.format(e))193- raise BadRequest()194-188 def _load_form_data(self):189 RequestBase._load_form_data(self)190 191 # In debug mode we're replacing the files multidict with an ad-hoc192 # subclass that raises a different error for key errors.200- ctx = _request_ctx_stack.top193+ ctx = _app_ctx_stack.top194 if ctx is not None and ctx.app.debug and \195 self.mimetype != 'multipart/form-data' and not self.files:196 from .debughelpers import attach_enctype_error_multidict197 attach_enctype_error_multidict(self)19 unmodified lines