Skip to content

Commit

Permalink
Bug: when using @view, returning an error response results in exception
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sgala committed Mar 4, 2010
1 parent cde3513 commit 20ed798
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,11 @@ def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kargs):
tplvars = dict(defaults)
tplvars.update(func(*args, **kargs))
return template(tpl_name, **tplvars)
result = func(*args, **kargs)
if isinstance(result, dict):
tplvars.update(result)
return template(tpl_name, **tplvars)
return result
return wrapper
return decorator

Expand Down
2 changes: 1 addition & 1 deletion homepage/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 20ed798

Please sign in to comment.