Skip to content

Revert orm model changes since v2.8.0 - #7517

Draft
agoscinski wants to merge 17 commits into
aiidateam:mainfrom
agoscinski:revert/orm-model
Draft

Revert orm model changes since v2.8.0#7517
agoscinski wants to merge 17 commits into
aiidateam:mainfrom
agoscinski:revert/orm-model

Conversation

@agoscinski

Copy link
Copy Markdown
Collaborator

Because these changes touch the public API, I decided to go through the effort and remove them for the release. Each commit is just a revert of the marked commit. Then at the end i applied pyupgrade --py310-plus on the files I have touched with the revert.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c05a1e9-d923-4a5b-b7fd-31bde29c9e43

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.11637% with 187 lines in your changes missing coverage. Please review.
✅ Project coverage is 29.96%. Comparing base (8a2747e) to head (2680e3f).

Files with missing lines Patch % Lines
src/aiida/orm/entities.py 37.10% 39 Missing ⚠️
src/aiida/orm/fields.py 62.00% 19 Missing ⚠️
src/aiida/orm/nodes/node.py 52.64% 18 Missing ⚠️
src/aiida/orm/nodes/data/code/portable.py 25.00% 15 Missing ⚠️
src/aiida/orm/nodes/data/array/array.py 35.00% 13 Missing ⚠️
src/aiida/cmdline/commands/cmd_code.py 20.00% 12 Missing ⚠️
src/aiida/cmdline/groups/dynamic.py 0.00% 12 Missing ⚠️
src/aiida/orm/nodes/data/code/abstract.py 47.37% 10 Missing ⚠️
src/aiida/orm/nodes/data/singlefile.py 33.34% 10 Missing ⚠️
src/aiida/orm/nodes/data/structure.py 47.06% 9 Missing ⚠️
... and 13 more

❗ There is a different number of reports uploaded between BASE (8a2747e) and HEAD (2680e3f). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (8a2747e) HEAD (2680e3f)
3 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7517       +/-   ##
===========================================
- Coverage   80.67%   29.96%   -50.71%     
===========================================
  Files         581      580        -1     
  Lines       46998    46303      -695     
===========================================
- Hits        37909    13868    -24041     
- Misses       9089    32435    +23346     

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

@agoscinski
agoscinski force-pushed the revert/orm-model branch 2 times, most recently from 885f2bd to 2a70de9 Compare August 3, 2026 20:37
@edan-bainglass

Copy link
Copy Markdown
Member

Because these changes touch the public API, I decided to go through the effort and remove them for the release. Each commit is just a revert of the marked commit. Then at the end i applied pyupgrade --py310-plus on the files I have touched with the revert.

This is a lot! Can you please clarify once more, just to be super clear, as to why we are reverting these changes? 🙏

This reverts commit f456028.

git rm aiida/orm/pydantic.py
git checkout --theirs -- .
git revert --continue
pytest --force-regen tests/orm/test_fields.py
They are required for all pyupgrade to allow forward declarations
git diff --diff-filter=d upstream/main HEAD --name-only -z -- '*.py' | xargs -0 uvx pyupgrade --py310-plus

`--diff-filter=d` to ignore deleted files whnen passing to pyupgrade
git diff --diff-filter=d upstream/main HEAD --name-only -z -- '*.py' | xargs -0 uv run pre-commit run --files

Run twice
git diff --diff-filter=d upstream/main HEAD --name-only -z -- '*.py' | xargs -0 uv run ruff check --fix --unsafe-fixes

verified manually if they match upstream/main changes
From commit 12f88f4 reapply changes
on src/aiida/orm/fields.py:

 `fields.py`: `extract_root_type` unwraps both `typing.Union` and the
 PEP 604 `types.UnionType`, so the rewrites do not degrade 207 ORM
 query fields across 40 classes to `QbAnyField` on Python 3.10-3.13.
Revert back to importlib_metadata
@agoscinski

Copy link
Copy Markdown
Collaborator Author

The pydantic orm model upgrade touches the public API a lot. It would be like 95% of our public API changes in the next release. You mentioned that by removing the automatic model rebuilds on initialization, the restapi test suite does not work properly. So the feature is not working properly as intended or introduces performance regression. That seems not something we want to ship. Also we soon will change how the ORM models work. so we completely break this API change again in 2-3 months. Even if is a valid break by semantic versioning, it seems unwise to ship something like this.

Reverting the commits was for me the safest option to remove it from the public API since not much manual work has to be done that needs to be reviewed. I marked all commits that are not just running commands with Manual at the beginning. In principle I could have also marked all Models as private with an underscore. That would be also fine for me as solution

@edan-bainglass

Copy link
Copy Markdown
Member

The pydantic orm model upgrade touches the public API a lot. It would be like 95% of our public API changes in the next release. You mentioned that by removing the automatic model rebuilds on initialization, the restapi test suite does not work properly. So the feature is not working properly as intended or introduces performance regression. That seems not something we want to ship. Also we soon will change how the ORM models work. so we completely break this API change again in 2-3 months. Even if is a valid break by semantic versioning, it seems unwise to ship something like this.

Reverting the commits was for me the safest option to remove it from the public API since not much manual work has to be done that needs to be reviewed. I marked all commits that are not just running commands with Manual at the beginning. In principle I could have also marked all Models as private with an underscore. That would be also fine for me as solution

Thanks for clarifying @agoscinski. No issue from my side. As discussed, we restore this on main, so I may continue developing the REST API (not yet released). Cheers 🙂

@edan-bainglass

edan-bainglass commented Aug 4, 2026

Copy link
Copy Markdown
Member

@agoscinski as a follow up, regarding the single failed test on the REST API, which fails due to an incorrect JSON schema title for the dynamic WriteModel (patched but now not resolved due to the removed model_rebuild call), I can resolve it as follows:

            WriteModel = cast(  # noqa: N806
                type[OrmModel],
                pdt.create_model(
                    name,
                    __config__=deepcopy(model_cls.model_config),  # lifted into the creation step
                    __base__=tuple(bases),
                    __module__=model_cls.__module__,
                    __qualname__=model_cls.__qualname__.replace(suffix, 'WriteModel'),  # lifted into the creation step
                    **model_fields,
                ),
            )
            # WriteModel.__qualname__ = model_cls.__qualname__.replace(suffix, 'WriteModel')
            WriteModel.__pydantic_decorators__.field_serializers = serializers
            WriteModel.__pydantic_decorators__.field_validators = validators
            # WriteModel.model_config = deepcopy(model_cls.model_config)
 `

By moving those two parts into the model creation, I no longer require a `model_rebuild`.

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.

2 participants