-
Notifications
You must be signed in to change notification settings - Fork 4
feat(sanity): check sample data file only if it is valid #269
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,5 +34,5 @@ def check(self, context: SanityContext) -> list[Reason] | None: | |
| return [ | ||
| Reason(f"File not found: {record['filename']}") | ||
| for record in records | ||
| if not data_root.joinpath(record["filename"]).exists() | ||
| if record.get("is_valid", True) and not data_root.joinpath(record["filename"]).exists() | ||
|
||
| ] or None | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ def check(self, context: SanityContext) -> list[Reason] | None: | |
| return [ | ||
| Reason(f"File not found: {record['info_filename']}") | ||
| for record in records | ||
| if record.get("info_filename") is not None | ||
| if record.get("is_valid", True) | ||
| and record.get("info_filename") is not None | ||
| and not data_root.joinpath(record["info_filename"]).exists() | ||
|
Comment on lines
+37
to
39
|
||
| ] or None | ||
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 comprehension can raise a KeyError if a SampleData record is missing the required "filename" key (e.g., malformed JSON): the filter only checks is_valid, but the element expression and exists() path both index record["filename"]. Since checkers are run without exception handling, this can crash the entire sanity run. Consider using record.get("filename") (or similar) and either skip missing filenames or emit a dedicated Reason for missing/empty filename before calling joinpath().