fix(ownership): validate reason+priority in QueueItemCreate to return 422 not 500
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
POST /ownership/queue with an invalid reason or priority was silently passing Pydantic and crashing at the DB layer (PostgreSQL enum type mismatch → 500). Added @field_validator for both fields, matching the existing validators in QueueItemPatch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -100,6 +100,28 @@ class QueueItemCreate(BaseModel):
|
||||
assigned_to: Optional[UUID] = None
|
||||
due_date: Optional[datetime] = None
|
||||
|
||||
@field_validator("reason")
|
||||
@classmethod
|
||||
def validate_reason(cls, v):
|
||||
from app.models.ownership_queue import QueueReason
|
||||
try:
|
||||
QueueReason(v)
|
||||
except ValueError:
|
||||
valid = [e.value for e in QueueReason]
|
||||
raise ValueError(f"Invalid reason '{v}'. Must be one of: {valid}")
|
||||
return v
|
||||
|
||||
@field_validator("priority")
|
||||
@classmethod
|
||||
def validate_priority(cls, v):
|
||||
from app.models.ownership_queue import QueuePriority
|
||||
try:
|
||||
QueuePriority(v)
|
||||
except ValueError:
|
||||
valid = [e.value for e in QueuePriority]
|
||||
raise ValueError(f"Invalid priority '{v}'. Must be one of: {valid}")
|
||||
return v
|
||||
|
||||
|
||||
class QueueItemOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
Reference in New Issue
Block a user