Validating value is unique
See original GitHub issueHi
I have a user schema with an email field. The email is validated to be unique:
class UserSchema(ma.Schema):
def validate_email(value):
return User.query.filter(User.email == value).first() is None
username = ma.fields.String()
email = ma.fields.Email(validate=validate_email)
This works great when creating users, but when updating a user with same email address it fails because there is already a user with same email address: the same user as the one being updated!
The validator unfortunately only has access to the email value so I can’t check if the user found is the same as the one being updated.
How do I best handle this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Excel formula: Data validation unique values only - Got It AI
To allow only unique values in a given range, you can use data validation with a custom formula based on the COUNTIF function....
Read more >Laravel Validator unique value - Stack Overflow
This rule will check if the email is unique where the brand has the given value. More information here : http://laravel.com/docs/validation#rule ...
Read more >Asking fields to be unique - FormValidation
Sometime the user need to fill multiple fields in form, also each of them must be unique. Any of them has to be...
Read more >Validating Data To Be Unique In Excel Range
Problem: Validating the values entered in column A, so that a value could not be entered more than once. Solution: use data validation...
Read more >Unique Record Validation - Tadabase
Depending on your requirements, checking fields for unique values can often be somewhat complex and can vary in complexity depending on your requirements....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would suggest moving such validation outside of schema:
You can use another schema for update.