I am using Pydantic to validate my payload. I have created a class like this -
class PayloadValidator(BaseModel):
"""
This model validates the payload structure and each attribute of payload.
"""
tenantId: str
emailId: List[str]
role: str
# means the payload emails are duplicate.
_duplicates: bool = False
# means the emails in payload are already used for the requesting tenants.
_existing: bool = False
# means the emails in payload are non corporate emails.
_non_corp_emails: bool = False
# final invite list
_valid_emails = List[str]
I want to perform certain validations on emailId. So I wrote couple of methods -
def email_format(a):
"""
raise an exception or return a tuple.
"""
pass
def email_existance(a,b,c):
"""
raise an exception or return a tuple.
"""
pass
def duplicate_emails(a):
"""
raise an exception or return a tuple.
"""
pass
Now these function are in a different module and I want to sequentially use it in __get__validator__(cls)
method of Pydantic.
The documentation says that I have to use yeild
. How can I make it work with my use case?