Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid Flask-Admin 2.1 warning "UserWarning: Fields missing from ruleset"?

Tags:

flask-admin

I'm using Flask-Admin 2.1 with Python 2.7.6.

One of my Flask-Admin model classes inherits from flask.ext.admin.contrib.sqla.ModelView and overrides form_rules.

When I run my application, this warning is displayed: "UserWarning: Fields missing from ruleset"

The warning is accurate: There are fields in my model that are not included in the ruleset. But that's by design. I don't want those fields to be displayed when users create or edit instances of this model.

I have already read this: https://github.com/flask-admin/flask-admin/pull/815#issuecomment-81963865

How can I suppress the warning?

like image 630
Steve Saporta Avatar asked Dec 04 '15 15:12

Steve Saporta


1 Answers

You can suppress the warning when the view is added by using this snippet with the assumed name UserView:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings('ignore', 'Fields missing from ruleset', UserWarning)
    admin.add_view(UserView())

Reference: https://docs.python.org/2/library/warnings.html#warnings.filterwarnings

like image 197
mikl Avatar answered Oct 06 '22 15:10

mikl