Skip to content

fix: remove redundant __init__ from CodeArchive model - #103

Merged
SHA888 merged 4 commits into
mainfrom
fix/code-archive-redundant-init
Jul 28, 2026
Merged

fix: remove redundant __init__ from CodeArchive model#103
SHA888 merged 4 commits into
mainfrom
fix/code-archive-redundant-init

Conversation

@SHA888

@SHA888 SHA888 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

What

Removed the custom __init__ from CodeArchive that manually re-implemented defaults already declared via Pydantic Field(default_factory=...) on the class attributes.

Why

The __init__ (previously lines 127-149) manually set defaults for id, created_at, updated_at, version, tags, visibility, is_archived, dependencies, and metadata — 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

  • Removed the def __init__(self, **data) method from CodeArchive
  • All defaults now flow through Pydantic's standard field-default machinery (which was already correct)

Behavioral note

The one minor behavioral difference: the old __init__ set updated_at = created_at when only created_at was supplied. With the Pydantic defaults, both created_at and updated_at independently default to datetime.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 by Field(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

    • Simplified code archive object initialization by relying on built-in field defaults instead of custom construction logic.
    • Preserved the expected behavior for update timestamps: when an update time isn’t provided, it now reliably mirrors the creation time to prevent subtle timestamp drift.
  • Documentation

    • Updated the maintenance checklist and tracking summary to reflect completion of one additional low-priority item.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@SHA888, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 44ae5962-ac7b-49d5-a57d-2dca7b5d0f41

📥 Commits

Reviewing files that changed from the base of the PR and between a838bd3 and 4a5dc49.

📒 Files selected for processing (2)
  • TODO.md
  • evoseal/models/code_archive.py
📝 Walkthrough

Walkthrough

The CodeArchive custom initializer was replaced with Pydantic defaults and a post-initialization hook that links updated_at to created_at only when omitted. The related TODO checklist and P3 tracking count were updated.

Changes

CodeArchive default initialization

Layer / File(s) Summary
Remove custom default initialization
evoseal/models/code_archive.py, TODO.md
CodeArchive now relies on Pydantic field defaults and conditionally mirrors created_at into updated_at, while preserving explicit timestamps. The related hygiene item is marked complete and the P3 count is updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: removing the redundant CodeArchive initializer.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/code-archive-redundant-init

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b71968b and a2ee329.

📒 Files selected for processing (2)
  • TODO.md
  • evoseal/models/code_archive.py
💤 Files with no reviewable changes (1)
  • evoseal/models/code_archive.py

Comment thread TODO.md Outdated
SHA888 added a commit that referenced this pull request Jul 28, 2026
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.
@SHA888

SHA888 commented Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Addressed the reviewer's point about drift.

What was wrong: The removed set updated_at = data["created_at"] when not explicitly provided, guaranteeing byte-for-byte equality. With the field defaults, each has its own independent default_factory=lambda: datetime.now(UTC), introducing microsecond drift.

Fix: Added model_post_init that sets self.updated_at = self.created_at on construction, restoring the original invariant. Verified:

  • Fresh archive: created_at == updated_at
  • After update(): updated_at > created_at
  • All 613 tests pass ✓

SHA888 added a commit that referenced this pull request Jul 28, 2026
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
@SHA888

SHA888 commented Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Addressed review feedback: model_post_init now guards the updated_at = created_at assignment with if "updated_at" not in self.model_fields_set, so explicit values survive deserialization (model_validate / model_validate_json). Verified: fresh construction still mirrors created_at; round-trip with distinct updated_at now preserves it. All 613 tests pass.

SHA888 added a commit that referenced this pull request Jul 28, 2026
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.
SHA888 added a commit that referenced this pull request Jul 28, 2026
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
@SHA888
SHA888 force-pushed the fix/code-archive-redundant-init branch from 398b809 to 9316ee9 Compare July 28, 2026 09:58
SHA888 added 4 commits July 28, 2026 09:58
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.
@SHA888
SHA888 force-pushed the fix/code-archive-redundant-init branch from 9316ee9 to 4a5dc49 Compare July 28, 2026 09:59
@SHA888
SHA888 merged commit 8d20a6c into main Jul 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant