Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileField / ImageField crash with WTForms >= 2.0 #138

Open
tito opened this issue May 29, 2015 · 2 comments
Open

FileField / ImageField crash with WTForms >= 2.0 #138

tito opened this issue May 29, 2015 · 2 comments

Comments

@tito
Copy link

tito commented May 29, 2015

The current dependency for Flask-SuperAdmin is Flask-WTF>=0.9 which itself install wtforms >= 1.0.4.

As for today, version for Flask-WTF is 0.11, and wtforms is 2.0.2.

The following model crash:

class Agenda(Document):
    image = ImageField()

Here is the crash:

Traceback (most recent call last):
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 266, in add
    % self.model.__name__)
Exception: The database model for 'Agenda' should have an __init__ with all arguments set to defaults.

But flask-superadmin is hiding the original error with a custom raise. After just changing the source code, the original exception is:

Traceback (most recent call last):
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 260, in add
    form = Form(obj=self.model())
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/form.py", line 212, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/form.py", line 18, in __init__
    super(BaseForm, self).__init__(obj=obj, prefix=prefix, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_wtf/form.py", line 96, in __init__
    *args, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/ext/csrf/form.py", line 21, in __init__
    super(SecureForm, self).__init__(formdata, obj, prefix, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/form.py", line 272, in __init__
    super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/form.py", line 52, in __init__
    field = meta.bind_field(self, unbound_field, options)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/meta.py", line 27, in bind_field
    return unbound_field.bind(form=form, **options)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/fields/core.py", line 346, in bind
    return self.field_class(*self.args, **kw)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/flask_superadmin/form.py", line 125, in __init__
    self._clear = self.clear_field.bind(form=None, name=self._clear_name, prefix=self._prefix, id=self._clear_id)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/fields/core.py", line 346, in bind
    return self.field_class(*self.args, **kw)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/fields/core.py", line 693, in __init__
    super(BooleanField, self).__init__(label, validators, **kwargs)
  File "/home/tito/.envs/2caps-backend/lib/python2.7/site-packages/wtforms/fields/core.py", line 92, in __init__
    raise TypeError("Must provide one of _form or _meta")
TypeError: Must provide one of _form or _meta

Which look like something new from the wforms in 2.0: "Class Meta paradigm allows customization of many aspects of WTForms".

See http://wtforms.readthedocs.org/en/latest/meta.html

@tito
Copy link
Author

tito commented May 29, 2015

I tried to debug it, but got lost into all the layers of abstraction in flask superadmin. The current fix is to downgrade wtforms to a version before 2.0, like 1.0.5.

Ie: pip install --upgrade wtforms==1.0.5

@genxstylez
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants