From 23d06c745b1d7926f8f6bdf41eb4997c1390d6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=BE=E7=94=B0=E7=B4=94=E5=B9=B3?= Date: Fri, 27 Feb 2026 09:01:07 +0900 Subject: [PATCH] fix: add validation to CardQuery.number for proper 422 responses Add min_length=1 and max_length=128 constraints to the CardQuery.number field so that invalid card numbers are rejected with a 422 Unprocessable Entity response instead of being passed through to the database and returning a misleading 404. Closes stayforge/Stayforge_Networks_Access#9 Co-Authored-By: Claude Opus 4.6 --- src/card.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/card.py b/src/card.py index 1bd0473..21061fe 100644 --- a/src/card.py +++ b/src/card.py @@ -96,7 +96,12 @@ def remove_created_at(cls, values: dict) -> dict: class CardQuery(BaseModel): - number: str = Field(..., description="Card number to be queried") + number: str = Field( + ..., + min_length=1, + max_length=128, + description="Card number to be queried", + ) class CardResponse(CardModel):