Commit 44438d87 authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #1293 from jmagnusson/raise-on-error

Allow exceptions to always be raised on view errors
parents 5a5001b4 371a8384
......@@ -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,7 +996,10 @@ class ModelView(BaseModelView):
# Error handler
def handle_view_exception(self, exc):
if isinstance(exc, IntegrityError):
flash(gettext('Integrity error. %(message)s', message=text_type(exc)), 'error')
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
return super(ModelView, self).handle_view_exception(exc)
......
......@@ -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
......
......@@ -73,6 +73,7 @@ setup(
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
test_suite='nose.collector'
)
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