Skip to content

Commit 341f81a

Browse files
幾田純平claude
authored andcommitted
fix: add field validation to CardQuery model for proper 422 responses (Closes stayforge/Stayforge_Networks_Access#9)
CardQuery.number was a plain str with no constraints, so invalid input (e.g., overly long strings) would pass validation and hit the database, returning 404 instead of 422. Added max_length=128, min_length=1, and alphanumeric pattern validation to match CardModel constraints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 134a447 commit 341f81a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/card.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def remove_created_at(cls, values: dict) -> dict:
9696

9797

9898
class CardQuery(BaseModel):
99-
number: str = Field(..., description="Card number to be queried")
99+
number: constr(min_length=1, max_length=128, pattern="^[a-zA-Z0-9]+$") = Field(..., description="Card number to be queried")
100100

101101

102102
class CardResponse(CardModel):

0 commit comments

Comments
 (0)