Skip to content

Pydantic schema for WorkGraphData#436

Draft
agoscinski wants to merge 1 commit intomainfrom
update-schema
Draft

Pydantic schema for WorkGraphData#436
agoscinski wants to merge 1 commit intomainfrom
update-schema

Conversation

@agoscinski
Copy link
Contributor

I used

datamodel-codegen --input src/aiida_workgraph/schemas/aiida_workgraph.schema.json --input-file-type jsonschema --output models.py

to create a pydantic model from the existing schema. I would change everywhere in the code the usage of the dict to the usage of the pydantic model. When passed in WorkGraph to the WorkGraphEngine the model is dumped to dict, then it is converted to the pydantic model again in WorkGraphEngine.

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2025

Codecov Report

Attention: Patch coverage is 95.78947% with 4 lines in your changes missing coverage. Please review.

Project coverage is 92.46%. Comparing base (898b6eb) to head (78b91be).

Files with missing lines Patch % Lines
src/aiida_workgraph/workgraph.py 55.55% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #436      +/-   ##
==========================================
+ Coverage   92.38%   92.46%   +0.07%     
==========================================
  Files          80       81       +1     
  Lines        5164     5256      +92     
==========================================
+ Hits         4771     4860      +89     
- Misses        393      396       +3     
Flag Coverage Δ
python-3.11 92.46% <95.78%> (+0.05%) ⬆️
python-3.12 92.48% <95.78%> (+0.07%) ⬆️
python-3.9 92.44% <95.78%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@superstar54
Copy link
Member

Hi @agoscinski , thanks for the work!

Currently, I think the pedantic model will be helpful in two places:

  • from_yaml, where we create the WorkGraph instance from a user-provided yaml file, e.g., comes from another engine or the common workflow.
  • in the workgraph's web application where fastapi is used. In this case, maybe we need to directly update the WorkGraphNode to a pedantic model. This maybe similar to the on-going work in the aiida-core (restapi)? The web application can be found in the aiida-workgraph-web-ui repo, e.g., in this file: https://github.com/aiidateam/aiida-workgraph-web-ui/blob/main/aiida_workgraph_web_ui/backend/app/workgraph.py

Note that the engine already dropped the usage of the wgdata and re-loaded the WorkGraph instance directly.

Please go ahead, maybe first update the from_yaml method, and then we can first merge the PR.

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.

3 participants