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

StringProperty validators not being respected #29

Open
hamx0r opened this issue Mar 25, 2020 · 0 comments
Open

StringProperty validators not being respected #29

hamx0r opened this issue Mar 25, 2020 · 0 comments

Comments

@hamx0r
Copy link

hamx0r commented Mar 25, 2020

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

@pallets-eco pallets-eco deleted a comment from alfi12388 Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant