Commit 04914876 authored by Jacob Magnusson's avatar Jacob Magnusson

Allow exceptions to always be raised on view errors

The current behavior to swallow exceptions makes it really hard to
track down bugs in the system. I would recommend to make this the default,
but I don’t want to impose so here’s a solution which requires the
config option `ADMIN_RAISE_ON_VIEW_EXCEPTION` to be set.
parent 5a5001b4
......@@ -10,7 +10,7 @@ from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql.expression import cast
from sqlalchemy import Unicode
from flask import flash
from flask import current_app, flash
from flask_admin._compat import string_types, text_type
from flask_admin.babel import gettext, ngettext, lazy_gettext
......@@ -996,6 +996,9 @@ class ModelView(BaseModelView):
# Error handler
def handle_view_exception(self, exc):
if isinstance(exc, IntegrityError):
if current_app.config.get('ADMIN_RAISE_ON_VIEW_EXCEPTION'):
raise
else:
flash(gettext('Integrity error. %(message)s', message=text_type(exc)), 'error')
return True
......
......@@ -7,8 +7,8 @@ from math import ceil
from werkzeug import secure_filename
from flask import (request, redirect, flash, abort, json, Response,
get_flashed_messages, stream_with_context)
from flask import (current_app, request, redirect, flash, abort, json,
Response, get_flashed_messages, stream_with_context)
from jinja2 import contextfunction
try:
import tablib
......@@ -1441,6 +1441,9 @@ class BaseModelView(BaseView, ActionsMixin):
flash(as_unicode(exc), 'error')
return True
if current_app.config.get('ADMIN_RAISE_ON_VIEW_EXCEPTION'):
raise
if self._debug:
raise
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment