Skip to content

Commit

Permalink
remove validator decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonra1993 committed Dec 10, 2023
1 parent efa5d2f commit 1f80402
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions backend/app/app/schemas/common_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from uuid import UUID
from app.utils.uuid6 import uuid7
from pydantic import BaseModel, validator
from pydantic import BaseModel, field_validator
from enum import Enum
from app.schemas.role_schema import IRoleRead

Expand Down Expand Up @@ -41,19 +41,19 @@ class IChatResponse(BaseModel):
message: str
type: str

@validator("id", "message_id", pre=True, allow_reuse=True)
@field_validator("id", "message_id")
def check_ids(cls, v):
if v == "" or v is None:
return str(uuid7())
return v

@validator("sender")
@field_validator("sender")
def sender_must_be_bot_or_you(cls, v):
if v not in ["bot", "you"]:
raise ValueError("sender must be bot or you")
return v

@validator("type")
@field_validator("type")
def validate_message_type(cls, v):
if v not in ["start", "stream", "end", "error", "info"]:
raise ValueError("type must be start, stream or end")
Expand Down
8 changes: 4 additions & 4 deletions backend/app/app/schemas/hero_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from app.models.team_model import TeamBase
from app.utils.partial import optional
from uuid import UUID
from pydantic import validator
from pydantic import field_validator


class IHeroCreate(HeroBase):
@validator("age", pre=True, check_fields=False, always=True)
def check_age(cls, value, values, **kwargs) -> int:
@field_validator('age')
def check_age(cls, value):
if value < 0:
raise ValueError("Invalida age")
raise ValueError("Invalid age")
return value


Expand Down

0 comments on commit 1f80402

Please sign in to comment.