You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ORM: Use pydantic to specify a schema for each ORM entity (aiidateam#6255)
This PR addresses [AEP
010](https://github.com/aiidateam/AEP/blob/983a645c9285ba65c7cf07fe6064c23e7e994c06/010_orm_schema/readme.md)
by introducing a schema interface for AiiDA's ORM entities using `pydantic`. The
goal is to make the structure and content of ORM classes introspectable and
serializable, enabling external applications—such as web APIs or CLIs—to
interface with AiiDA in a programmatic, schema-driven way. Each core ORM class
now defines a `Model` subclass that exposes its fields using rich metadata
annotations. These models support conversion to and from ORM instances
(`_from_model`, `_to_model`), as well as a user API yielding JSON-compatible
formats (`from_serialized`, `serialize`). The serialization mechanism is
experimental and is stated to the user as such on use of the serialization
methods.
In the process of implementing the original proposal, the `MetadataField`
utility was extended with additional metadata such as `exclude_to_orm`,
`exclude_from_cli`, `orm_class`, `orm_to_model`, and `model_to_orm`, enabling
precise control over how fields behave across layers. A helper function
`get_metadata` was added to facilitate metadata retrieval from `FieldInfo`
objects.
The PR refactors the `AuthInfo`, `Comment`, and `PortableCode` classes to adopt
this new schema interface. For `AuthInfo` and `Comment`, equality checks are now
defined based on the models to improve testability and object comparison. The
`PortableCode` now also supports `PurePath` for the `filepath_executable` on
initialization, though the type of its model's `filepath_files` is corrected to
`str` only, reflecting how it is stored in the database. The serialization of
repository files is unified for the `filepath_files` field and yaml-export
functionality.
For objects with repository-stored files, on serialization, files are written to
a user-specified directory (or a temporary one if not provided) and the paths
are stored in the serialized model. The `from_serialized` method can then be
used to reconstruct the object, including its files, from the serialized data.
Furthemore, CLI support was also expanded: dynamic option generation now
respects `exclude_from_cli` and allows prioritizing or customizing CLI arguments
using schema metadata. The `create_code` command and dynamic group listing logic
were updated accordingly to use the new models for constructing instances.
Additionally, entry points were registered for core ORM classes to improve
plugin discoverability, and a new `FilePath` typing alias was introduced for
shared use across the codebase.
---------
Co-authored-by: Edan Bainglass <[email protected]>
Co-authored-by: Alexander Goscinski <[email protected]>
Co-authored-by: Alexander Goscinski <[email protected]>
0 commit comments