-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Hi there. I think there is a bug. What I'm trying to do is to check if atleast one of two properties (login or dn) exists. But I if set them optional, validator is never called.
This example doesn't raise exception.
from typing import Optional
import pydantic
from pydantic import validator
class Authentication(pydantic.BaseModel):
login: Optional[str]
dn: Optional[str]
password: str
@validator('login', "dn", always=True, pre=True)
def auth_specified(cls, value, values, **kwargs):
if not value and not {"login", "dn"}.intersection(values.keys()):
raise ValueError("No auth specified")
return value
Authentication(password="asdd")Checked on github master branch.
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X