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 ...@@ -10,7 +10,7 @@ from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql.expression import cast from sqlalchemy.sql.expression import cast
from sqlalchemy import Unicode 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._compat import string_types, text_type
from flask_admin.babel import gettext, ngettext, lazy_gettext from flask_admin.babel import gettext, ngettext, lazy_gettext
...@@ -996,6 +996,9 @@ class ModelView(BaseModelView): ...@@ -996,6 +996,9 @@ class ModelView(BaseModelView):
# Error handler # Error handler
def handle_view_exception(self, exc): def handle_view_exception(self, exc):
if isinstance(exc, IntegrityError): 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') flash(gettext('Integrity error. %(message)s', message=text_type(exc)), 'error')
return True return True
......
...@@ -7,8 +7,8 @@ from math import ceil ...@@ -7,8 +7,8 @@ from math import ceil
from werkzeug import secure_filename from werkzeug import secure_filename
from flask import (request, redirect, flash, abort, json, Response, from flask import (current_app, request, redirect, flash, abort, json,
get_flashed_messages, stream_with_context) Response, get_flashed_messages, stream_with_context)
from jinja2 import contextfunction from jinja2 import contextfunction
try: try:
import tablib import tablib
...@@ -1441,6 +1441,9 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1441,6 +1441,9 @@ class BaseModelView(BaseView, ActionsMixin):
flash(as_unicode(exc), 'error') flash(as_unicode(exc), 'error')
return True return True
if current_app.config.get('ADMIN_RAISE_ON_VIEW_EXCEPTION'):
raise
if self._debug: if self._debug:
raise raise
......
...@@ -73,6 +73,7 @@ setup( ...@@ -73,6 +73,7 @@ setup(
'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
], ],
test_suite='nose.collector' 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