-
Notifications
You must be signed in to change notification settings - Fork 232
Update node serialization/deserialization and other Pydantic issues #6990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 77.60% 77.54% -0.06%
==========================================
Files 566 566
Lines 43549 43721 +172
==========================================
+ Hits 33793 33899 +106
- Misses 9756 9822 +66 ☔ 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
Also some that are no longer required
4c1c1a0 to
e27bff4
Compare
TODO
|
| """Create a new `Code` instance.""" | ||
| try: | ||
| instance = cls._from_model(cls.Model(**kwargs)) | ||
| model = cls.InputModel(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More is said about InputModel in later comments. For now, understand that this is intended as a derived model from an ORM class's model, stripping away all read-only fields (marked with exclude_to_orm=True) and is used by the CLI and REST API for node creation.
| key='exclude_from_cli', | ||
| default=False, | ||
| ): | ||
| if get_metadata(field_info, key='exclude_from_cli'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The None default serves the same purpose
| # FIXME resolve this hardcoded special case properly | ||
| if field_name == 'filepath_files': | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer here we explicitly hardcode 'filepath_files', as it is the intended exclusion here. is_attribute is used for other purposes, not for marking exclusion from the CLI show command. Reminding @GeigerJ2 to open an issue (optionally reply here with a link to the issue).
Some parts of the ORM module do not pass a serialization round trip. This PR addresses this, but further discussion is needed regarding what should actually be (de)serialized. If interested, good to read aiidateam/AEP#40 and discussion on #6255. Some discussion regarding mismatch between an object's constructor args and its Model fields can be found here.
Good to also discuss if the use of pydantic should be extended to ORM instance creation in general, not only by way of
from_serialized. This is not implemented in this PR (and is out of scope) but can be addressed in a follow-up PR if deemed "correct".Open questions
repository_content. The current implementation usesbase64encoding/decoding, but this is clearly not ideal for large files. Some discussion was had w.r.t switching to links to some online storage of files. TBDUpdates
The PR now also introduces the following:
Dataplugins viaattributesattributesinDataplugins (not allowed in the backend node)InputModel- a derived view of the defined entityModelsuitable forEntitycreationNote 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.