Skip to content
Snippets Groups Projects
Commit b4cf45ee authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Disable flask-admin unique validator

Trying to insert an invalid IP or network address raises an exception.
This is due to the unique validator from flask-admin that queries the
database.

The unique validator is automatically added for columns with
unique=True. The only way to disable it is to monkey patch the Unique
class.
This allows the field validator to catch invalid format.

IntegrityError are already catched anyway.
parent 8dc4a249
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,15 @@ from .validators import IPNetwork ...@@ -17,6 +17,15 @@ from .validators import IPNetwork
from ..models import ICS_ID_RE from ..models import ICS_ID_RE
# Monkey patch flask-admin Unique validator to disable it
# Flask-admin automatically adds an unique validator that queries
# the database. For some fields like INET and MACADDR, if the value
# is invalid the database raises an exception. It's nicer to let the
# field validator catches the incorrect format.
# It's also better to let the database catch unicity error anyway.
sqla.form.Unique.__call__ = lambda x, y, z: None
# Add custom model converter for CIText type # Add custom model converter for CIText type
# See https://github.com/flask-admin/flask-admin/issues/1196 # See https://github.com/flask-admin/flask-admin/issues/1196
class AppAdminModelConverter(sqla.form.AdminModelConverter): class AppAdminModelConverter(sqla.form.AdminModelConverter):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment