Skip to content

Cache derived minimal model on specific class - #7539

Open
edan-bainglass wants to merge 1 commit into
aiidateam:mainfrom
edan-bainglass:minimal-model-cache-bug-fix
Open

Cache derived minimal model on specific class#7539
edan-bainglass wants to merge 1 commit into
aiidateam:mainfrom
edan-bainglass:minimal-model-cache-bug-fix

Conversation

@edan-bainglass

Copy link
Copy Markdown
Member

The previous mechanism caused subclasses to end up with the same cached minimal model as their parent class.

The previous mechanism caused subclasses to end up with the same cached
minimal model as their parent class.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

_as_minimal_model now avoids inherited minimal-model caches. A regression test verifies that Node and Data minimal models remain distinct when submodels are involved.

Changes

Minimal model cache isolation

Layer / File(s) Summary
Class-local cache lookup and regression test
src/aiida/orm/pydantic.py, tests/orm/models/test_models.py
_as_minimal_model reads _AIIDA_MINIMAL_MODEL from the current class dictionary. The test verifies distinct minimal models for orm.Node.ReadModel and orm.Data.ReadModel.

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

Possibly related PRs

Suggested reviewers: agoscinski

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes caching the derived minimal model on the specific class, which matches the main change.
Description check ✅ Passed The description directly explains the subclass caching issue addressed by the pull request.
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.

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.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.67%. Comparing base (299e945) to head (afb50b3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7539      +/-   ##
==========================================
- Coverage   80.68%   80.67%   -0.01%     
==========================================
  Files         581      581              
  Lines       47068    47068              
==========================================
- Hits        37972    37967       -5     
- Misses       9096     9101       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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.

🧹 Nitpick comments (1)
tests/orm/models/test_models.py (1)

521-524: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Also verify child-model idempotency.

This test proves that orm.Data.ReadModel does not reuse ParentMinimalModel. It does not prove that repeated calls reuse ChildMinimalModel. Add a second call and an identity assertion.

Proposed test addition
     assert ChildMinimalModel is not ParentMinimalModel
+    RepeatedChildMinimalModel = orm.Data.ReadModel._as_minimal_model()  # noqa: N806
+    assert RepeatedChildMinimalModel is ChildMinimalModel
🤖 Prompt for 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.

In `@tests/orm/models/test_models.py` around lines 521 - 524, Extend
test_minimal_model_idempotency_with_submodels by calling
orm.Data.ReadModel._as_minimal_model() a second time and asserting the returned
object is identical to ChildMinimalModel, while preserving the existing
assertion that child and parent minimal models differ.
🤖 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.

Nitpick comments:
In `@tests/orm/models/test_models.py`:
- Around line 521-524: Extend test_minimal_model_idempotency_with_submodels by
calling orm.Data.ReadModel._as_minimal_model() a second time and asserting the
returned object is identical to ChildMinimalModel, while preserving the existing
assertion that child and parent minimal models differ.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0fe1001f-6569-4c8a-a4b2-ad0a9708f109

📥 Commits

Reviewing files that changed from the base of the PR and between 299e945 and afb50b3.

📒 Files selected for processing (2)
  • src/aiida/orm/pydantic.py
  • tests/orm/models/test_models.py

@edan-bainglass

Copy link
Copy Markdown
Member Author

@GeigerJ2 here's an example of a suggestion that should not be accepted, as such a test already exists in isolation (directly above this new one). I'm wondering then if the rabbit only scans and comments on the new code. If so, we should be careful!

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