Skip to content

Instantly share code, notes, and snippets.

@ShahriyarR
Created December 6, 2022 18:03
Show Gist options
  • Save ShahriyarR/80e54801fcbee00c1e98491da6461bd3 to your computer and use it in GitHub Desktop.
Save ShahriyarR/80e54801fcbee00c1e98491da6461bd3 to your computer and use it in GitHub Desktop.
from pydantic import BaseModel, validator
class InvalidDBCredentialsModel(BaseModel):
comment: str
password: Password
uri: DBUri
port: DBPort
host: DBHost
@validator("password")
def password_length_check(cls, v):
passwd = v.get_secret()
if len(passwd) > 7:
v.add_secret(passwd)
return v
raise ValueError("Password length should be more than 7")
class Config:
arbitrary_types_allowed = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment