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

refactor: migrates rule validation to pydantic #207

Merged
merged 11 commits into from
Apr 24, 2024

Conversation

jpower432
Copy link
Contributor

@jpower432 jpower432 commented Apr 8, 2024

Description

Removes classes related to custom validation and uses pydantic for custom validation relating to the TrestleRule model.
The output of validation failures were not clear so with this change, the clarity was improved.

Fixes #205

Rationale

Field validations should not be optional, but there may be a use-case where we need optional validation. This can be handled with the trestle Validator classes. Thus, there should be no need for classes supporting validation in this project.

Type of change

  • Feat/Maintenance - Moves validation to pydantic and enhance the workflow around rule validation

How has this been tested?

  • Tested in demo repository Updated example
  • Unit tests added for validation error reporting

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@jpower432 jpower432 added the enhancement New feature or request label Apr 12, 2024
@jpower432 jpower432 added this to the 0.9.0 milestone Apr 16, 2024
@jpower432 jpower432 changed the title [WIP] refactor: migrates rule validation to pydantic [WIP] feat: migrates rule validation to pydantic Apr 18, 2024
@jpower432 jpower432 changed the title [WIP] feat: migrates rule validation to pydantic [feat: migrates rule validation to pydantic Apr 18, 2024
@jpower432 jpower432 requested a review from beatrizmcouto April 18, 2024 23:14
@jpower432 jpower432 changed the title [feat: migrates rule validation to pydantic feat: migrates rule validation to pydantic Apr 18, 2024
@jpower432 jpower432 marked this pull request as ready for review April 18, 2024 23:14
Copy link
Contributor

@beatrizmcouto beatrizmcouto left a comment

Choose a reason for hiding this comment

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

Reviewed during paired code review today. Example of updated error messages attached.

@jpower432 jpower432 changed the title feat: migrates rule validation to pydantic refactor: migrates rule validation to pydantic Apr 19, 2024
@jpower432 jpower432 requested a review from beatrizmcouto April 19, 2024 21:18
@jpower432
Copy link
Contributor Author

jpower432 commented Apr 19, 2024

@beatrizmcouto Rebased this branch after the merge of #195. PTAL at minor changes in 73a3ea2.

Pydantic custom rule validation and error handling with some
minor tweaks supports can accomplish what the goal was for the
ValidationHandler class. Removing in favor of a more cohesive
validation solution.

Signed-off-by: Jennifer Power <[email protected]>
To make the YAML test data more readable, define the alternative
paramerer mappings in proper YAML.

Signed-off-by: Jennifer Power <[email protected]>
The default key value can be set automatically during transformation
to keep it from being defined twice in YAML. If defined twice, it will
just be validated that it matches the default value string.

Signed-off-by: Jennifer Power <[email protected]>
When the CLI errors, the error logs are not very clear and the error
should multiple times. This will help make the error more readable.

Signed-off-by: Jennifer Power <[email protected]>
For validation with pydantic per YAML file, we want to collect
all of the validation errors up front and give a consistent, detailed message
for an efficient workflow.

Signed-off-by: Jennifer Power <[email protected]>
The path contains the component information making the
file easier to indentify for fixing errors.

Signed-off-by: Jennifer Power <[email protected]>
Renamed variable to be more descriptive and removes extra call to
errors() method

Signed-off-by: Jennifer Power <[email protected]>
@jpower432 jpower432 force-pushed the refactor/rule-validations branch from 8d53c30 to 73a3ea2 Compare April 20, 2024 01:40
Copy link
Contributor

@beatrizmcouto beatrizmcouto left a comment

Choose a reason for hiding this comment

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

Approved formatting of error message update and deduplication of a small part of the code

@jpower432 jpower432 merged commit 10421a3 into main Apr 24, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move custom rule validation logic and error handling to pydantic
2 participants