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

Form Validation of None Values #4

Closed
wants to merge 5 commits into from
Closed

Conversation

lucasvo
Copy link
Contributor

@lucasvo lucasvo commented Aug 23, 2012

It's not the prettiest solution but without fixing mongoengine's email validation, this will have to do

If you setup the following resource form:

class SomeDocument(Document):
     email = EmailField(required=False)
     name = StringField()

ResourceFormBase = model_form(SomeDocument, exclude=['email'])
class ResourceForm(ResourceFormBase):
    email = fields.TextField(validators=[validators.optional(), validators.email()])

A POST with the following json: {'name':'John Doe'} fails without these changes.

Because form.data returns: {'name':'John Doe', 'email':''} instead of {'name':'John Doe'} which causes a validation error. There might be other consequences of this behavior.

lucasvo and others added 5 commits August 12, 2012 22:10
i
If you have an email field in a document that is optional but are using a wtform for the Resource validation, mongoengine will raise an error because
wtforms returns '' instead of None for an empty email field. This doesn't pass validation of mongoengine.
@travisbot
Copy link

This pull request passes (merged cd4e965 into 8ab7866).

@anemitz
Copy link
Member

anemitz commented Aug 23, 2012

Can you provide a test case which shows the failure for several field types?

@lucasvo
Copy link
Contributor Author

lucasvo commented Aug 24, 2012

The problem lies in flask-mongoengine.wtf: MongoEngine/flask-mongoengine#9 I'm not sure if it makes sense adding this hotfix here. I'll see how i can fix flask-mongoengine.

@anemitz
Copy link
Member

anemitz commented Aug 31, 2012

closing this issue as it has moved to flask-mongoengine.

@anemitz anemitz closed this Aug 31, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants