Update node serialization/deserialization and other Pydantic issues#6990
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6990 +/- ##
==========================================
+ Coverage 80.28% 80.37% +0.10%
==========================================
Files 577 578 +1
Lines 45545 46112 +567
==========================================
+ Hits 36562 37060 +498
- Misses 8983 9052 +69 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9b7cfbd to
d83ced6
Compare
|
@khsrali regarding one of the failed tests... In this PR, I lift some validation to the top of the constructor (of stash data classes - see 91e4ad5), to avoid any operations if the object is bound to fail. However, this seems to introduce failures in testing them. It suggests that perhaps there is some order to the operations, though I don't see it. Can you please comment? |
It was checking for |
|
@GeigerJ2 okay, this is ready for others to inspect. I did my best to isolate the commits and provided comments on each. Happy to discuss further. Pinging also @agoscinski @superstar54 if interested. Pinging @sphuber for input/feedback, if he has time. |
|
It may be possible to rely on the post models of aiida-restapi as a reference for defining ORM constructor parameters, as the post models are intended to represent serialized objects passed to the REST API for object construction. Looking into this. |
c8ded01 to
476e144
Compare
476e144 to
7c191fa
Compare
|
@danielhollas what is this about? Nevermind. I see that importing |
516a6df to
2c3e5df
Compare
Nice, the system works. :-) Feel free to improve the error message here to make it more obvious that this is about the |
d6e44ff to
0b37ef6
Compare
|
|
@danielhollas what do you think about ignoring Ruff N806 - "~variable should be lowercase"? See case below. |
Do you mean ignoring locally (fine) or globally? |
Global. There are many cases when the variable is a class, not an instance. I've pushed this in my last commit just to verify that it works. Okay with removing it in favor of local handling, but would like to hear the reason against a global N806 rule. UpdateNice. Ignoring N806 globally raised a whole lot of RUF100 due to the codebase being littered with local N806 rules. I'd say that supports my case 🙂 |
|
@danielhollas done for tonight. Will revisit this in the morning 😴 |
Yeah, running Seems fine to remove it, or alternatively, use the e.g. something like this in pyproject.toml In any case please open a separate PR for that so we don't polute this one with bikeshedding discussion and unrelated changes. |
Thanks @danielhollas. Then for this one, since there are only a few cases in my PR, I will locally ignore them. Will open a PR for the pattern handling shortly after. |
5faafb0 to
a4a5b3e
Compare
- Rename `orm/model.py` as `orm/pydantic.py` - Move ORM part of `MetadataField` to `orm/pydantic.py:OrmMetadataField` (wraps `MetadataField`) - Leverage `OrmMetadataField` in ORM package - Rename `_orm_to_model_field_values` as `_to_model_field_values` - Rename `_model_to_orm_field_values` as `_to_orm_field_values` and move into `OrmModel` - Cast ORM constructor and CLI models as OrmModel extensions instead of `AiiDABaseModel`
Developers can override it to control serialization.
mbercx
left a comment
There was a problem hiding this comment.
(still) LGTM! 🚀
I had a quick look at the new docs, as we discussed, but it's tricky to meaningfully review them without understanding the changes and how they are used. One should probably try to implement a new data type with the models/fields to see if the documentation has any gaps. If I get around to that, I'll cycle back and give a more useful review/feedback of the documentation.

This PR addresses several issues with #6255 that came up during updates to the aiida-restapi in aiidateam/aiida-restapi#93.
Major changes
Entity.serialize()) are removed due to impracticality.Nodesubclass Models no longer extendNode.Model. Instead,Node.Model.attributesis typed asNode.AttributesModel, which is concretely implemented byNodesubclasses with explicit attributes definition (see this issue for details).Codemodels still extendNode.Modelhere and there for CLI metadata support.AttributesModelrefactor. Of note is that now node construction from model will pass arguments toNodeORM constructors under the attributes key. As such, constructors are adjusted to account for this. This change also supportsNodecreation via the RESTAPI.Note for PR reviewers
There are a few changes that are likely out of scope. These will move to dedicated PRs prior to merge of this PR.
Happy to discuss 🙂