Skip to content
This repository was archived by the owner on Oct 12, 2024. It is now read-only.

StringProperty validators not being respected #29

@hamx0r

Description

@hamx0r

I have a wtf_appengine form defined with:

PostForm = ndb.model_form(Post, base_class=flask_wtf.FlaskForm, exclude=vars(AuditMixin),
                          field_args={
                              'summary': {'widget': widgets.TextArea(), 'render_kw': {'class': 'form-control'},
                                          'validators': [validators.Length(max=1500)]},
                              'essay': {'widget': widgets.TextArea(), 'render_kw': {'class': 'form-control'}}
                          })

which pulls from the NDB POST class:

class Post(ndb.Model, AuditMixin):
    author = ndb.KeyProperty(verbose_name='author', kind=User)
    headline = ndb.StringProperty(verbose_name='headline', required=True)
    summary = ndb.StringProperty(verbose_name='summary', required=True)
    essay = ndb.TextProperty(verbose_name='essay', required=False)

Even though PostForm has a validator setting max length to 1500 (which is what a StringProperty will allow), if i try to submit the PostForm, it will fail to validate with error:

{'summary': [u'Field cannot be longer than 500 characters.', u'Field cannot be longer than 500 characters.']}

It appears that adding a validator using ndb.model_form does not replace the default validators, but rather either extends them or ignores them.

This could be fixed by changing the StringProperty based validator to allow for 1500 chars instead of just 500

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions