flask-wtf
flask-wtf copied to clipboard
Meta passed to FlaskForm init may be None
The definition of Form at http://wtforms.readthedocs.io/en/latest/forms.html#wtforms.form.Form.init has meta=None, which should be preserved by subclasses.
Since 0.14, Flask-WTF assumes that meta is a dict if present in kwargs. This breaks wtforms-json, which preserve the WTForms default.
See also https://github.com/kvesteri/wtforms-json/issues/47.
Since I got an email requesting for an example, here is one:
$ cat example.py
from flask import Flask
from flask_wtf import FlaskForm
from wtforms import StringField
import wtforms_json
class ExampleForm(FlaskForm):
example = StringField()
wtforms_json.init()
app = Flask('example')
with app.test_request_context('/'):
myjson = {'example': 'passed'}
goodform = ExampleForm.from_json(myjson, meta={}, csrf_enabled=False)
print 'Goodform', goodform.example.data
badform = ExampleForm.from_json(myjson, csrf_enabled=False)
$ python example.py
Goodform passed
Traceback (most recent call last):
File "example.py", line 19, in <module>
badform = ExampleForm.from_json(myjson, csrf_enabled=False)
File "/usr/local/lib/python2.7/dist-packages/wtforms_json/__init__.py", line 233, in from_json
**kwargs
File "/usr/local/lib/python2.7/dist-packages/wtforms/form.py", line 212, in __call__
return type.__call__(cls, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_wtf/form.py", line 85, in __init__
kwargs.setdefault('meta', {}).setdefault('csrf', csrf_enabled)
AttributeError: 'NoneType' object has no attribute 'setdefault'
Thanks, I dug through it in the mean time and figured out what you were referring to.
Fixed in release 0.14.2 on PyPI.