-
Notifications
You must be signed in to change notification settings - Fork 8
feat: experiment library schema changes, ingestion report with errors, json schema warnings #435
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
Open
v-rocheleau
wants to merge
26
commits into
develop
Choose a base branch
from
features/library-strategies
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e9cf81d
xml parsing
v-rocheleau 2f765da
xsd ontologies utils
v-rocheleau e479e4c
lint
v-rocheleau 26becc3
experiment library strategy data migration
v-rocheleau 762d23a
xsd dir name change
v-rocheleau a32bd01
fix poetry.lock
v-rocheleau 1390066
code clean
v-rocheleau d8d9a85
lint
v-rocheleau d030cb6
read library selection, add doc
v-rocheleau 48ff585
fix test data
v-rocheleau 2a93fe4
fix migration type
v-rocheleau eb93de0
migration fix, lint
v-rocheleau fae4540
add validation error descriptions to IngestError
v-rocheleau 0c1cb1b
ingest response format
v-rocheleau 9f8ff0c
ingestion error responds with warnings on schema changes
v-rocheleau 2194a08
update api ingestion tests
v-rocheleau 948f6bc
lint
v-rocheleau db378d2
add ingestion tests, exp workflow payload schema
v-rocheleau 881f792
infer success from status code
v-rocheleau b359973
remove line call
v-rocheleau 9b58dc4
get ingestion warnings from derived experiment results ingestion
v-rocheleau dd0f66c
save ingest report to file and output
v-rocheleau 74e55fa
Merge branch 'develop' into features/library-strategies
v-rocheleau f9fa0f9
fix migrations, lint
v-rocheleau 4148d36
schema changes version update
v-rocheleau bbef730
fix api ingest tests
v-rocheleau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,113 @@ | ||
| from typing import List, Optional | ||
| from jsonschema.exceptions import ValidationError | ||
| from chord_metadata_service import __version__ | ||
| from chord_metadata_service.experiments.schemas import EXPERIMENT_SCHEMA_CHANGES | ||
| from chord_metadata_service.chord.data_types import DATA_TYPE_EXPERIMENT, DATA_TYPE_PHENOPACKET | ||
|
|
||
| __all__ = [ | ||
| "IngestError", | ||
| ] | ||
|
|
||
|
|
||
| DATA_TYPE_SCHEMA_CHANGES = { | ||
| DATA_TYPE_EXPERIMENT: EXPERIMENT_SCHEMA_CHANGES, | ||
| DATA_TYPE_PHENOPACKET: None | ||
| } | ||
|
|
||
|
|
||
| def parse_validation_errors(errors: List[ValidationError]) -> Optional[List[dict]]: | ||
| """ | ||
| Accepts a list of jsonschema ValidationError and converts them to a client error format. | ||
|
|
||
| Parameters: | ||
| errors (List[ValidationError]): errors raised by jsonschema during validation | ||
| Returns: | ||
| List[dict]: | ||
| dict: | ||
| schema_path (str): Schema path string (e.g "properties.library_strategy") | ||
| faulty_value (str | obj): The value at the schema_path causing the error | ||
| property_schema (dict): JSON schema of the property (includes valid options) | ||
| message (str): The ValidationError.message | ||
| """ | ||
| error_descriptions = [] | ||
| for error in errors: | ||
| schema_path = ".".join(error.schema_path) | ||
| error_descriptions.append({ | ||
| "schema_path": schema_path, | ||
| "faulty_value": error.instance, | ||
| "message": error.message, | ||
| "property_schema": error.schema, | ||
| }) | ||
| return error_descriptions if len(error_descriptions) else None | ||
|
|
||
|
|
||
| def parse_property_warnings(data: dict, prop_name: str, property_changes: List[tuple]) -> Optional[dict]: | ||
| for (old_value, new_value) in property_changes: | ||
| value = data[prop_name] | ||
| property_warning = { | ||
| "property_name": prop_name, | ||
| "property_value": value, | ||
| "deprecated_value": old_value, | ||
| "suggested_replacement": new_value, | ||
| } | ||
|
|
||
| if value == old_value: | ||
| # Naive comparison for dicts | ||
| return property_warning | ||
|
|
||
| if isinstance(value, str) and isinstance(old_value, str): | ||
| # Lower case comparison for string values (JSON schema enum) | ||
| if value.lower() == old_value.lower(): | ||
| return property_warning | ||
|
|
||
| # Only warn when mecessary | ||
| return None | ||
|
|
||
|
|
||
| def parse_schema_warnings(data: dict, schema: dict) -> Optional[List[dict]]: | ||
| """ | ||
| Schema warnings are issued on Katsu releases that include schema changes. | ||
| Warnings are returned to highlight schema changes that may be the root cause of an IngestionError. | ||
|
|
||
| Parameters: | ||
| data (dict): the data submitted for ingestion | ||
|
|
||
| Returns: | ||
| List[dict]: | ||
| dict: | ||
| property_name (str): The name of the property | ||
| property_value (str | dict) | ||
| deprecated_value (str | dict): The deprecated property option | ||
| suggested_replacement (str | dict): The new suggested property option | ||
| version (str): The Katsu release version associated with the schema change | ||
| """ | ||
| if not data or not schema: | ||
| return None | ||
|
|
||
| data_type = schema.get("$id", "").split(":")[-1] | ||
| applicable_changes = DATA_TYPE_SCHEMA_CHANGES.get(data_type, None) | ||
|
|
||
| if not applicable_changes or __version__ not in applicable_changes: | ||
| # Skip if data type's schema is not affected in current Katsu version | ||
| return None | ||
|
|
||
| warnings = [] | ||
| for (version, version_changes) in applicable_changes.items(): | ||
| for (prop_name, changes) in version_changes.get("properties", {}).items(): | ||
| if property_warning := parse_property_warnings(data, prop_name, changes): | ||
| property_warning["version"] = version | ||
| warnings.append(property_warning) | ||
| return warnings if len(warnings) else None | ||
|
|
||
|
|
||
| class IngestError(Exception): | ||
| pass | ||
|
|
||
| def __init__(self, | ||
| data: dict = None, | ||
| schema: dict = None, | ||
| schema_validation_errors: List[ValidationError] = [], | ||
| message="An error occured during ingestion."): | ||
|
|
||
| self.validation_errors = parse_validation_errors(schema_validation_errors) | ||
| self.schema_warnings = parse_schema_warnings(data=data, schema=schema) | ||
| self.message = message | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.