wtforms-appengine icon indicating copy to clipboard operation
wtforms-appengine copied to clipboard

StringProperty validators not being respected

Open hamx0r opened this issue 5 years ago • 0 comments

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

hamx0r avatar Mar 25 '20 20:03 hamx0r