-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: no longer shortcircuit validation if there are parameter referen…
…ce errors (#71) Problem: The improvement to validation errors implemented in #47 introduced an error. If there are errors flagged for parameter references (e.g. definition of an unknown variable) then we are aborting the rest of the model validation. This can make diagnosing errors in a template harder than it should be. The root of the bug is that pydantic itself short-circuits model parsing if any pre-root-validator raises an error. For example, validation of the following template will not show that the field 'parmeterDefinitions' is unknown (it should be 'parameterDefinitions' -- notice the missing 'a' in 'para'): ``` specificationVersion: jobtemplate-2023-09 name: DemoJob parmeterDefinitions: - name: Foo type: INT steps: - name: DemoStep script: actions: onRun: command: "{{Param.Foo}}" ``` Solution: I had to move the variable reference validation out of pydantic's validation flows. It doesn't work as a regular root validator (see the other PR for why), and we can't have it short-circuiting validation as a pre-root-validator. So, instead I've updated the _parse_model() function to run the variable reference validation if the model has a _root_template_prevalidator method defined. This does come with a trade-off. We no longer run the template variable validation at all if the user is directly constructing a data model using the model classes. Adding a __init__() to JobTemplate and EnvironmentTemplate to force the validator to run ended up in doubling-up all variable reference validation errors. So, this'll have to be a tradeoff that we accept until a better solution comes around. Signed-off-by: Daniel Neilson <53624638+ddneilson@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters