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

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

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

No branches or pull requests

1 participant