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

unable to render a HiddenField? #150

Open
stablum opened this issue Nov 1, 2019 · 0 comments
Open

unable to render a HiddenField? #150

stablum opened this issue Nov 1, 2019 · 0 comments

Comments

@stablum
Copy link

stablum commented Nov 1, 2019

Hi,

a field in my ORM class is the following:

    created_at = Column(
        DateTime(),
        server_default=now(),
        info={
            'form_field_class':wtforms.fields.HiddenField
        }

As you can see this is a field that is supposed to be handled automatically by the DBMS and never touched again after the INSERT.

Anyways, I have to put it in the form because on the edit form it's going to be used to populate the ORM object, and if the form field is missing, then created_at will be zeroed to a null string before the UPDATE.

Unfortunately it seems that the HiddenField cannot be rendered in my jinja template and generates an Exception with the following stacktrace:

Traceback (most recent call last):
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/francesco/.local/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.7/dist-packages/flask_basicauth.py", line 108, in wrapper
    return view_func(*args, **kwargs)
  File "/home/francesco/unknownelectronics/web.py", line 163, in organize_artist
    return handle_organize_page(model.artist.Artist, ArtistForm, id=id)
  File "/home/francesco/unknownelectronics/web.py", line 127, in handle_organize_page
    form = formclass()
  File "/home/francesco/.local/lib/python3.7/site-packages/wtforms/form.py", line 212, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/home/francesco/.local/lib/python3.7/site-packages/wtforms_alchemy/__init__.py", line 291, in __init__
    super(ModelForm, self).__init__(*args, **kwargs)
  File "/home/francesco/.local/lib/python3.7/site-packages/flask_wtf/form.py", line 88, in __init__
    super(FlaskForm, self).__init__(formdata=formdata, **kwargs)
  File "/home/francesco/.local/lib/python3.7/site-packages/wtforms/form.py", line 272, in __init__
    super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
  File "/home/francesco/.local/lib/python3.7/site-packages/wtforms/form.py", line 52, in __init__
    field = meta.bind_field(self, unbound_field, options)
  File "/home/francesco/.local/lib/python3.7/site-packages/wtforms/meta.py", line 27, in bind_field
    return unbound_field.bind(form=form, **options)
  File "/home/francesco/.local/lib/python3.7/site-packages/wtforms/fields/core.py", line 353, in bind
    return self.field_class(*self.args, **kw)
TypeError: __init__() got an unexpected keyword argument 'format'

Any idea on how to solve this? Is flask-alchemy not supposed to support hidden fields?

best,
-Francesco

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

1 participant