Skip to content

Commit

Permalink
Add categories validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Fudster committed Jan 9, 2025
1 parent 532471e commit fd31b4b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/pydiscordsh/pydiscordsh/api/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, List
import os
from sqlmodel import Field, Session, SQLModel, create_engine, select, JSON, Column
from pydantic import validator

class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
Expand Down Expand Up @@ -38,6 +39,13 @@ class DiscordServer(SQLModel, table=True):

class Config:
arbitrary_types_allowed = True
validate_assignment = True

@validator("categories", pre=True, always=True)
def validate_categories(cls, value):
if value and len(value) > 2:
raise ValueError("Categories list cannot have more than 2 items.")
return value

# class BumpVote(SQLModel, table=False)

Expand Down

0 comments on commit fd31b4b

Please sign in to comment.