-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
@validates accepts multiple field names #1965
base: dev
Are you sure you want to change the base?
@validates accepts multiple field names #1965
Conversation
apologies for the long delay on this. i hesitated initially because i had the same concern as @deckar01 about this being a breaking change. now that we're closing to releasing the next major, i think this is one that we can get merged. i'll update this when i have some time |
should validator methods receive from marshmallow import Schema, fields, validates, ValidationError
class UserSchema(Schema):
name = fields.Str(required=True)
nickname = fields.Str(required=True)
@validates("name", "nickname")
def validate_names(self, value: str, field_name: str) -> str:
if len(value) < 3:
raise ValidationError(f"{field_name} too short")
return value |
looks like SQLAlchemy does pass a from sqlalchemy.orm import validates
class EmailAddress(Base):
__tablename__ = "address"
id = mapped_column(Integer, primary_key=True)
email = mapped_column(String)
@validates("email")
def validate_email(self, key, address):
if "@" not in address:
raise ValueError("failed simple email validation")
return address |
Updated to pass |
Fix for #1960