fix: sort_by Literal validation not enforced — invalid values silently ignored #66
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#66
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
GET /api/v3/players?season=13&sort_by=INVALIDreturns 200 with a full result set instead of a 422 validation error.Reproduction
Expected
422 Unprocessable Entity — invalid
sort_byvalue should be rejected.Root Cause
The
sort_byparameter inapp/routers_v3/views.pywas updated in this release (#36) to use aLiteraltype annotation, but FastAPI is not enforcing the validation at the route level. Likely the parameter is declared asOptional[str]in the route signature and theLiteralcheck is happening downstream (or not at all) rather than at the FastAPI parameter binding layer.Fix
Declare
sort_bydirectly asOptional[Literal["name", "team", ...]]in the FastAPI route function signature so FastAPI's automatic validation rejects unknown values with a 422 before the handler runs.Discovered
Post-deploy smoke test against production — 2026-03-17.
PR #68 opens the fix: #68
Fix: Changed
sort: Optional[str]→sort: Optional[Literal["cost-asc", "cost-desc", "name-asc", "name-desc"]]in theget_playersroute signature and addedLiteralto the typing imports.FastAPI now rejects unknown
sortvalues with 422 at binding time. Valid values were derived from_apply_player_sortinplayer_service.py. Existing callers (discord-app-v2) already use the valid values so no breaking change.