-
Notifications
You must be signed in to change notification settings - Fork 6
Replace direct jsonschema use with LinkML validation tools
#1287
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 |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| from dagster import op, AssetMaterialization, AssetKey, MetadataValue | ||
| from jsonschema import Draft7Validator | ||
| from nmdc_runtime.util import get_nmdc_jsonschema_dict | ||
| from nmdc_runtime.util import get_nmdc_schema_validator | ||
| from toolz import dissoc | ||
|
|
||
| from nmdc_runtime.site.resources import mongo_resource | ||
|
|
@@ -61,19 +60,19 @@ def validate_mongo_collection(context, collection_name: str): | |
| collection = mongo_db[collection_name] # get mongo collection | ||
| db_set = collection_name.split(".")[0] | ||
|
|
||
| validator = Draft7Validator(get_nmdc_jsonschema_dict()) | ||
| validator = get_nmdc_schema_validator() | ||
| validation_errors = [] | ||
|
|
||
| for count, doc in enumerate(collection.find()): | ||
| # add logging for progress? | ||
| # e.g.: if count % 1000 == 0: context.log.info(“done X of Y") | ||
| doc = dissoc(doc, "_id") # dissoc _id | ||
| errors = list(validator.iter_errors({f"{db_set}": [doc]})) | ||
| if len(errors) > 0: | ||
| report = validator.validate({f"{db_set}": [doc]}, target_class="Database") | ||
| if len(report.results) > 0: | ||
| if "id" in doc.keys(): | ||
| errors = {doc["id"]: [e.message for e in errors]} | ||
| errors = {doc["id"]: [r.message for r in report.results]} | ||
| else: | ||
| errors = {f"missing id ({count})": [e.message for e in errors]} | ||
| errors = {f"missing id ({count})": [r.message for r in report.results]} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in the validator plugin architecture, I can specify low-level warnings and info, right? these still count as errors here?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, individual validation results can have various severities (info, warning, error, fatal). In practice the two validation plugins we're using only ever produce results with the |
||
| validation_errors.append(errors) | ||
|
|
||
| return {"collection_name": collection_name, "errors": validation_errors} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.