diff options
author | Santiago Gala <sgala@apache.org> | 2010-03-04 13:47:15 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2010-03-11 22:24:46 +0100 |
commit | 2d0f2d8034a4e12263233fdb9ac83be41b6f2b47 (patch) | |
tree | cf52fc666b83756f9b636b3872415d872b6fcd2d | |
parent | 7904ea9ac76fe4dbc0aac44eedc6505700372320 (diff) | |
download | bottle-2d0f2d8034a4e12263233fdb9ac83be41b6f2b47.tar.gz |
Bug: when using @view, returning an error response results in exception
The @view wrapper expects a dictionary of vars. It
tries to update the defaults with the returned values,
and this fails for errors.
The bottle.py patch checks and only updates and calls
the template if the result is a dict.
The app.py patch raises errors instead of using return, and
so escapes the view processing.
Missing: test cases
-rwxr-xr-x | bottle.py | 9 | ||||
-rwxr-xr-x | homepage/app.py | 2 |
2 files changed, 7 insertions, 4 deletions
@@ -1581,9 +1581,12 @@ def view(tpl_name, **defaults): def decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): - tplvars = dict(defaults) - tplvars.update(func(*args, **kwargs)) - return template(tpl_name, **tplvars) + result = func(*args, **kwargs) + if isinstance(result, dict): + tplvars = defaults.copy() + tplvars.update(result) + return template(tpl_name, **tplvars) + return result return wrapper return decorator diff --git a/homepage/app.py b/homepage/app.py index 434b303..e5fd23c 100755 --- a/homepage/app.py +++ b/homepage/app.py @@ -112,7 +112,7 @@ def page(name='start'): if p.exists: return dict(page=p) else: - return bottle.HTTPError(404, 'Page not found') + raise bottle.HTTPError(404, 'Page not found') # raise to escape the view... @route('/rss.xml') |