We're using http://flask-admin.readthedocs.org/ for a quick admin interface. Our model has constraints defined as follows:
__table_args__ = (
db.UniqueConstraint(user_id, role, domain_id),
db.UniqueConstraint(user_id, role, customer_id),
)
When saving a record that violates a constraint while in debug mode, the app stops with a traceback. If not in debug mode, it reports the error in a flash message and rolls back the transaction.
This is the desired behaviour (i.e. flash message and rollback). The user did something wrong and was protected from entering bad data: it's not an error that should show a traceback.
What is the proper Flask way of handling such exceptions elegantly? Should I be overriding the {create,update,delete}_model
methods of ModelView
?