Move random.randint default out of Pydantic model field #24

Closed
opened 2026-02-20 06:53:19 +00:00 by cal · 1 comment
Owner

`app/routers_v2/mlbplayers.py:40` — `offense_col: int = random.randint(1, 3)`. Pydantic evaluates field defaults at class definition time, not request time. Every MLB player gets the same random value. Use `Field(default_factory=lambda: random.randint(1, 3))`.

Priority: medium

\`app/routers_v2/mlbplayers.py:40\` — \`offense_col: int = random.randint(1, 3)\`. Pydantic evaluates field defaults at class definition time, not request time. Every MLB player gets the same random value. Use \`Field(default_factory=lambda: random.randint(1, 3))\`. **Priority**: medium
cal added the
bug
label 2026-02-20 06:53:19 +00:00
cal added the
ai-working
label 2026-03-03 20:05:07 +00:00
cal added the
ai-pr-opened
label 2026-03-03 20:05:45 +00:00
Author
Owner

Fixed in PR #38: #38

Changed offense_col: int = random.randint(1, 3) to offense_col: int = pydantic.Field(default_factory=lambda: random.randint(1, 3)) in app/routers_v2/mlbplayers.py. The bare default was evaluated once at class definition time — every instance shared the same value for the process lifetime. The default_factory ensures a fresh random value per instantiation.

Fixed in PR #38: https://git.manticorum.com/cal/paper-dynasty-database/pulls/38 Changed `offense_col: int = random.randint(1, 3)` to `offense_col: int = pydantic.Field(default_factory=lambda: random.randint(1, 3))` in `app/routers_v2/mlbplayers.py`. The bare default was evaluated once at class definition time — every instance shared the same value for the process lifetime. The `default_factory` ensures a fresh random value per instantiation.
cal removed the
ai-working
label 2026-03-03 20:06:28 +00:00
cal closed this issue 2026-03-03 21:46:47 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-database#24
No description provided.