-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[components] Enrich pydantic validation errors with filepaths, line numbers #26962
base: master
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
954424c
to
54d3e9d
Compare
@@ -3,6 +3,6 @@ | |||
- key: customers | |||
|
|||
- command: "python customer_stats.py" | |||
assets: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm?
both error reporting and populating source position information. | ||
""" | ||
try: | ||
model = parse_obj_as(cls, obj_parse_root.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is deprecated:
'parse_obj_as
is deprecated. Use pydantic.TypeAdapter.validate_python
instead.',
def from_file(contents: str, filepath: str) -> "ComponentFileModel": | ||
parsed = parse_yaml_with_source_positions(contents, filepath) | ||
obj = _parse_and_populate_model_with_annotated_errors( | ||
cls=ComponentFileModel, obj_parse_root=parsed, obj_key_path_prefix=[] | ||
) | ||
|
||
obj._source_position_tree = parsed.source_position_tree # noqa: SLF001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create a new non-pydantic class that represents the File and all metadata about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need code smell article for this one :-)
Summary
Ports over the YAML line tracking functionality to enrich Pydantic
ValidationErrors
thrown when instantiating components. The filepath of the loaded YAML file & offending line number are appended to the error message.Test Plan
New set of validation integration tests.