You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like the unique flag in MongoEngine is not reflected properly in the WTForms validation. I have a model like this (where the email is unique):
class User(database.Document):
""" User model """
email = database.EmailField(required=True, unique=True)
first_name = database.StringField(required=True, max_length=30)
last_name = database.StringField(required=True, max_length=30)
password = database.StringField(required=True)
is_active = database.BooleanField(default=False)
is_authenticated = database.BooleanField(default=False)
But when I save this I get a mongoengine.errors.NotUniqueError from MongoEngine. I expected to get an error message from the form validation instead.
The text was updated successfully, but these errors were encountered:
Validation takes place at field level. The form itself can't tell if the document is unique. It would need to query the DB. That's not something WTForms does.
I've been facing the same issue. For now, I've left it aside and I catch NotUniqueError in the controller, but perhaps I could setup a function to query the DB and wrap this into a custom validator.
Agreed w/ @lafrech that this is not something that the form validation should deal with. Catching mongoengine.errors.NotUniqueError and then responding with a validation error message sounds like a perfectly fine approach.
It seems like the
unique
flag in MongoEngine is not reflected properly in the WTForms validation. I have a model like this (where theemail
is unique):But when I save this I get a
mongoengine.errors.NotUniqueError
from MongoEngine. I expected to get an error message from the form validation instead.The text was updated successfully, but these errors were encountered: