fix: use Field(default_factory) for offense_col random default (#24) #38
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#38
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database-24"
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
Fixes #24 —
offense_colinPlayerModelwas using a barerandom.randint(1, 3)as the field default. Pydantic evaluates bare defaults at class definition time (once, on import), so everyPlayerModelinstance received the same random integer foroffense_colthroughout the lifetime of the process.Replaced with
pydantic.Field(default_factory=lambda: random.randint(1, 3))so a fresh random value is generated on each model instantiation.Files Changed
app/routers_v2/mlbplayers.py— line 40:offense_coldefault changed to usedefault_factoryTest Results
No test suite in this repo. Change verified by reading back the modified file — import of
pydanticalready present;pydantic.Fieldusage is consistent with the existing module-level import pattern.AI Code Review
Files Reviewed
app/routers_v2/mlbplayers.py(modified)Findings
Correctness
random.randint(1, 3)as a class-level default is evaluated once at module import time, making allPlayerModelinstances share the sameoffense_colvalue for the lifetime of the process.Field(default_factory=lambda: random.randint(1, 3))defers evaluation to instantiation time, which is the intended behavior.random(line 2) andpydantic(line 7) are already imported — no new dependencies added.randint(1, 3)range is preserved (inclusive on both ends: 1, 2, or 3).pydantic.Field(...)form is consistent with the rest of the file's use ofpydantic.BaseModel.Security
Style & Conventions
Suggestions
Verdict: APPROVED
Correct, minimal fix for a classic Python evaluated-at-definition-time default pitfall.
Field(default_factory=...)is the idiomatic Pydantic v1 solution. No concerns — ready to merge.Automated review by Claude PR Reviewer
d26bc0dc7bto6130eb993f