hmarr / mongoengine

[Moved to mongoengine/mongoengine]
https://github.com/MongoEngine/mongoengine
MIT License
793 stars 20 forks source link

EmailField fails on validation for empty strings and does not provide for required = False #577

Closed ghost closed 11 years ago

ghost commented 12 years ago

While failing on empty strings is absolutely correct, it would be nice to have email fields to not fail on validation when they have been declared as required = False.

My proposal would be to extend upon the BaseField._validate method to check for whether the field is required, and test for whether it is either None or empty after a white space strip, and return early if either is the case.

The rationale of this is that it will save you a lot of extra code in your application where you have to (django that is)

if form.cleaned_data['email']: document.email = form.cleaned...

TIA!

rozza commented 11 years ago

This is fixed in 0.7.9