FlaskWTFDeprecationWarning with Flask_Security
Asked Answered
C

2

7

I am received a warning every time I use Flask Security.

FlaskWTFDeprecationWarning: "flask_wtf.Form" has been renamed to "FlaskForm" 
and will be removed in 1.0.

Is this an issue with Flask Security or something I could address myself? I am using Flask-Security==1.7.5

from flask_security import current_user, login_required, RoleMixin, Security, \
SQLAlchemyUserDatastore, UserMixin, utils

I don't seem to import Flask_WTF directly.

Coad answered 29/9, 2016 at 23:42 Comment(1)
Short answer: it's Flask-Security, but it is something you could address yourself by updating the library. Feel free to comment on my answer below if anything is unclear.Stettin
S
10

It looks like 1.7.5 is the latest release of Flask-Security. And the latest version of Flask-WTF is 0.13 (make sure you have that installed by checking a pip freeze).

Since you don't use Flask-WTF directly, the issue isn't your code. The issue is coming from Flask-Security's code itself, which has Flask-WTF as a dependency.

The way that Flask-Security imports the Form class from Flask-WTF is deprecated, so you're seeing the error when this line runs:

from flask_wtf import Form as BaseForm

https://github.com/mattupstate/flask-security/blob/e01cd63a214969cf8e4ee800d398e1c43b460c7f/flask_security/forms.py#L15

You can either open an issue on Flask-Security (feel free to link to this question) or submit a pull request yourself to the author updating this line to the non-deprecated import

from flask_wtf import FlaskForm as BaseForm

Make sure to run tests before / after too before submitting.

For a little more context, you can use git blame to see the commit that last changed the deprecated import line in Flask-Security (6f68f1d) on August 15, 2013.

Doing the same on Flask-WTF, you can see that the deprecation was introduced in 42cc475 on June 30, 2016.

Stettin answered 30/9, 2016 at 0:45 Comment(1)
I should point out that you also have various options for just suppressing the warnings without modifying Flask-Security (e.g., #14463777). Still updating it helps the whole community so everyone doesn't have to suppress the same warning.Stettin
G
11

My answer is not inherent to your exact situation. However, the same warning message occurs when we code this:

from flask_wtf import Form

To fix this problem, you should use FlaskForm in place of Form:

from flask_wtf import FlaskForm

This is highlighted on GitHub and I just want to share the solution here to help any eventual doer who might face it in the future.

Gibbs answered 12/9, 2017 at 8:0 Comment(0)
S
10

It looks like 1.7.5 is the latest release of Flask-Security. And the latest version of Flask-WTF is 0.13 (make sure you have that installed by checking a pip freeze).

Since you don't use Flask-WTF directly, the issue isn't your code. The issue is coming from Flask-Security's code itself, which has Flask-WTF as a dependency.

The way that Flask-Security imports the Form class from Flask-WTF is deprecated, so you're seeing the error when this line runs:

from flask_wtf import Form as BaseForm

https://github.com/mattupstate/flask-security/blob/e01cd63a214969cf8e4ee800d398e1c43b460c7f/flask_security/forms.py#L15

You can either open an issue on Flask-Security (feel free to link to this question) or submit a pull request yourself to the author updating this line to the non-deprecated import

from flask_wtf import FlaskForm as BaseForm

Make sure to run tests before / after too before submitting.

For a little more context, you can use git blame to see the commit that last changed the deprecated import line in Flask-Security (6f68f1d) on August 15, 2013.

Doing the same on Flask-WTF, you can see that the deprecation was introduced in 42cc475 on June 30, 2016.

Stettin answered 30/9, 2016 at 0:45 Comment(1)
I should point out that you also have various options for just suppressing the warnings without modifying Flask-Security (e.g., #14463777). Still updating it helps the whole community so everyone doesn't have to suppress the same warning.Stettin

© 2022 - 2024 — McMap. All rights reserved.