fix: remove redundant __init__ from CodeArchive model - #103
Conversation
|
Warning Review limit reached
Next review available in: 26 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesCodeArchive default initialization
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@TODO.md`:
- Line 311: Update the Total row in the Markdown table so it contains four
cells, adding an empty fourth cell while preserving the existing Total label and
values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e31d9956-efe1-4052-94ac-00a4b3964364
📒 Files selected for processing (2)
TODO.mdevoseal/models/code_archive.py
💤 Files with no reviewable changes (1)
- evoseal/models/code_archive.py
Add model_post_init to restore the guarantee that updated_at mirrors created_at when a CodeArchive is first created. Without this, the two independent Field(default_factory=lambda: datetime.now(UTC)) calls introduce microsecond drift, silently breaking the invariant the old custom __init__ maintained. Addresses reviewer feedback on PR #103.
|
Addressed the reviewer's point about drift. What was wrong: The removed set Fix: Added
|
model_post_init unconditionally set self.updated_at = self.created_at, silently discarding any real updated_at value on deserialization (model_validate / model_validate_json). This broke round-tripping and lost edit history. Now only overwrites when updated_at was not explicitly provided. Ref: PR #103 review feedback
|
Addressed review feedback: |
Add model_post_init to restore the guarantee that updated_at mirrors created_at when a CodeArchive is first created. Without this, the two independent Field(default_factory=lambda: datetime.now(UTC)) calls introduce microsecond drift, silently breaking the invariant the old custom __init__ maintained. Addresses reviewer feedback on PR #103.
model_post_init unconditionally set self.updated_at = self.created_at, silently discarding any real updated_at value on deserialization (model_validate / model_validate_json). This broke round-tripping and lost edit history. Now only overwrites when updated_at was not explicitly provided. Ref: PR #103 review feedback
398b809 to
9316ee9
Compare
The custom __init__ manually set defaults (id, created_at, updated_at, version, tags, visibility, is_archived, dependencies, metadata) that are already declared via Pydantic Field(default_factory=...) on the class attributes. This created two sources of truth — a drift hazard where changing one set of defaults without the other silently produces inconsistent behavior. Removing the custom __init__ lets Pydantic handle all default generation through its standard machinery, eliminating the duplication. Addresses TODO.md P3 item: 'models/code_archive.py:127-149 __init__ manually re-implements every default already provided by Field(default_factory=...)'
Add model_post_init to restore the guarantee that updated_at mirrors created_at when a CodeArchive is first created. Without this, the two independent Field(default_factory=lambda: datetime.now(UTC)) calls introduce microsecond drift, silently breaking the invariant the old custom __init__ maintained. Addresses reviewer feedback on PR #103.
model_post_init unconditionally set self.updated_at = self.created_at, silently discarding any real updated_at value on deserialization (model_validate / model_validate_json). This broke round-tripping and lost edit history. Now only overwrites when updated_at was not explicitly provided. Ref: PR #103 review feedback
- Fix misleading parenthetical in model_post_init docstring: deserialization supplies updated_at explicitly, so the branch is skipped, not triggered. The example now correctly references fresh programmatic construction. - Add missing fourth cell to Total row in TODO.md summary table (MD056). Reviewer point on missing field defaults is already handled — all seven fields (id, version, tags, visibility, is_archived, dependencies, metadata) have Field(default_factory=...) or plain defaults. No change needed. Reviewer point on wasted datetime.now() is noted but negligible; the alternatives (Optional type, sentinel) add complexity for no real gain.
9316ee9 to
4a5dc49
Compare
What
Removed the custom
__init__fromCodeArchivethat manually re-implemented defaults already declared via PydanticField(default_factory=...)on the class attributes.Why
The
__init__(previously lines 127-149) manually set defaults forid,created_at,updated_at,version,tags,visibility,is_archived,dependencies, andmetadata— all of which are already declared via Pydantic field defaults on the class. This created two sources of truth: changing one set of defaults without the other silently produces inconsistent behavior (a drift hazard).What changed
def __init__(self, **data)method fromCodeArchiveBehavioral note
The one minor behavioral difference: the old
__init__setupdated_at = created_atwhen onlycreated_atwas supplied. With the Pydantic defaults, bothcreated_atandupdated_atindependently default todatetime.now(UTC). In practice this is more correct — the two timestamps reflect when the object was actually constructed, not a synthetic alias.Addresses
TODO.md P3 item:
models/code_archive.py:127-149—__init__manually re-implements every default already provided byField(default_factory=...)Verification
ruff format --check .✅ruff check evoseal/ tests/✅pytest tests/unit/models/test_code_archive.py -v→ 9 passed ✅pytest tests/(full suite) → 613 passed, 23 deselected ✅Summary by CodeRabbit
Refactor
Documentation