Skip to content
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

Parser.parse_from_node: Validate outputs against process spec #6159

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Oct 21, 2023

The parse_from_node clasmethod is a utility function to call the parse method of a Parser implementation for a given CalcJobNode. It automatically calls parse in the correct manner, passing the retrieved output node, and wrapping it in a calcfunction to optionally store the provenance.

However, since the calcfunction by default has a dynamic output namespace and so accepts all outputs, it would not perform the same output validation that the original CalcJob would have done since that most likely will have defined specific outputs. Especially given that the parse_from_node method would often be used in unit tests to test Parser implementations, having the output validation be different would make it possible to mis bugs. For example, if the parser assigns an invalid output node, this would go unnoticed.

The parse_from_node is updated to patch the output specification of the calcfunction with that of the process class that was used to created the CalcJobNode which is being passed as an argument. As long as the process can of course be loaded. This ensures that when the calcfunction return the outputs returned by Parser.parse they are validated against the output specification of the original CalcJob class. If it fails, a ValueError is raised.

The `parse_from_node` clasmethod is a utility function to call the
`parse` method of a `Parser` implementation for a given `CalcJobNode`.
It automatically calls `parse` in the correct manner, passing the
`retrieved` output node, and wrapping it in a calcfunction to optionally
store the provenance.

However, since the `calcfunction` by default has a dynamic output
namespace and so accepts all outputs, it would not perform the same
output validation that the original `CalcJob` would have done since that
most likely will have defined specific outputs. Especially given that
the `parse_from_node` method would often be used in unit tests to test
`Parser` implementations, having the output validation be different
would make it possible to mis bugs. For example, if the parser assigns
an invalid output node, this would go unnoticed.

The `parse_from_node` is updated to patch the output specification of
the `calcfunction` with that of the process class that was used to
created the `CalcJobNode` which is being passed as an argument. As long
as the process can of course be loaded. This ensures that when the
`calcfunction` return the outputs returned by `Parser.parse` they are
validated against the output specification of the original `CalcJob`
class. If it fails, a `ValueError` is raised.
@sphuber sphuber requested a review from mbercx October 21, 2023 18:22
@sphuber
Copy link
Contributor Author

sphuber commented Oct 21, 2023

@mbercx this would have caught the bug in the Q2rParser for which we just merged the fix

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sphuber, LGMT!

@sphuber sphuber merged commit d16792f into aiidateam:main Oct 23, 2023
17 checks passed
@sphuber sphuber deleted the fix/parse-from-node-output-spec branch October 23, 2023 08:46
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