Skip to content
Myr

Request local objects now fail properly with a RuntimeError. This fixes #105

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

authored by Armin Ronacher · committed by Armin Ronacher · parent d17b6d7 · Browse files · 4 files+26 added−5 removed
This commit

State

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

Diff stats

4 files+26 added−5 removed

  • tests:+5 added−1 removed
  • other:+21 added−4 removed

4 files+26 added−5 removed

modified:docs/upgrading.rst+8 added
17 unmodified lines
18installation, make sure to pass it the ``-U`` parameter::1920 $ easy_install -U Flask2122Version 0.723-----------2425Due to a bug in earlier implementations the request local proxies now26raise a :exc:`RuntimeError` instead of an :exc:`AttributeError` when they27are unbound. If you cought these exceptions with :exc:`AttributeError`28before, you should catch them with :exc:`RuntimeError` now.2930Version 0.631-----------3233Flask 0.6 comes with a backwards incompatible change which affects the
87 unmodified lines
modified:flask/globals.py+11 added-4 removed
8 unmodified lines
9 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213from functools import partial14from werkzeug import LocalStack, LocalProxy1516def _lookup_object(name):17 top = _request_ctx_stack.top18 if top is None:19 raise RuntimeError('working outside of request context')20 return getattr(top, name)2122# context locals23_request_ctx_stack = LocalStack()17current_app = LocalProxy(lambda: _request_ctx_stack.top.app)18request = LocalProxy(lambda: _request_ctx_stack.top.request)19session = LocalProxy(lambda: _request_ctx_stack.top.session)20g = LocalProxy(lambda: _request_ctx_stack.top.g)24current_app = LocalProxy(partial(_lookup_object, 'app'))25request = LocalProxy(partial(_lookup_object, 'request'))26session = LocalProxy(partial(_lookup_object, 'session'))27g = LocalProxy(partial(_lookup_object, 'g'))
modified:tests/flask_tests.py+5 added-1 removed
70 unmodified lines
71 assert index() == 'Hello World!'72 ctx.pop()73 try:74 index()75 except AttributeError:75 except RuntimeError:76 pass77 else:78 assert 0, 'expected runtime error'79
388 unmodified lines
468 pass469 else:470 assert "Expected ValueError"471472 def test_request_locals(self):473 self.assertEqual(repr(flask.g), '<LocalProxy unbound>')474 self.assertFalse(flask.g)475476477class JSONTestCase(unittest.TestCase):478479 def test_jsonify(self):480 d = dict(a=23, b=42, c=[1, 2, 3])
714 unmodified lines
modified:CHANGES+2 added
9 unmodified lines
1011- Added :meth:`~flask.Flask.make_default_options_response`12 which can be used by subclasses to alter the default13 behaviour for `OPTIONS` responses.14- Unbound locals now raise a proper :exc:`RuntimeError` instead15 of an :exc:`AttributeError`.1617Version 0.6.118-------------19
151 unmodified lines