Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exception on jinja template while having cache failure #565

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/flask_caching/jinja2ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,23 @@ def _cache(self, timeout, fragment_name, vary_on, caller):

#: Delete key if timeout is 'del'
if timeout == "del":
cache.delete(key)
return caller()

rv = cache.get(key)
if rv is None:
rv = caller()
cache.set(key, rv, timeout)
return rv
try:
cache.delete(key)
return caller()
except Exception as e:
if cache.app.debug:
raise e
else:
return caller()

try:
rv = cache.get(key)
if rv is None:
rv = caller()
cache.set(key, rv, timeout)
return rv
except Exception as e:
if cache.app.debug:
raise e
else:
return caller()
Loading