linkml / linkml-validator

[retired]
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Unexpected validation failure in testing #15

Closed glass-ships closed 1 year ago

glass-ships commented 1 year ago

I'm doing some development on Koza testing, and have run into an unexpected validation error against the Biolink model... I might be missing something obvious, but was hoping someone might have input.

Here's the error we're getting:

>       assert result.valid == True
E       assert False == True
E        +  where False = ValidationResult(plugin_name='JsonSchemaValidationPlugin', valid=False, validation_messages=[ValidationMessage(severit..., field=None, value=None, message="Additional properties are not allowed ('category', 'id', 'name' were unexpected)")]).valid

which seems to suggest that category, id, and name aren't valid slots for a named thing (?)

Here's the test code that yields the error: ```python from pathlib import Path import pytest from linkml_validator.validator import Validator valid_gene = { "id": "BOGUS:12345", "name": "Bogus Gene 12345", "category": ["biolink:NamedThing", "biolink:Gene"], } invalid_gene = { "name": "Bogus Gene 98765", "type": "biolink:NamedThing" } model_schema = Path(__file__).parent.parent / 'resources' / 'biolink-model.yaml' @pytest.mark.parametrize("gene", [valid_gene]) def test_valid_input(gene): validator = Validator(schema="tests/resources/biolink-model.yaml") v = validator.validate(obj=gene, target_class="Entity") result = v.validation_results[0] assert result.valid == True @pytest.mark.parametrize("gene", [invalid_gene]) def test_invalid_input(gene): validator = Validator(schema="tests/resources/biolink-model.yaml") v = validator.validate(obj=gene, target_class="NamedThing") result = v.validation_results[0] assert result.valid == False ```
deepakunni3 commented 1 year ago

@glass-ships Thank you for the detailed message and sample code to reproduce the issue.

I tried locally with the validator and Biolink Model v3.0.3 (https://raw.githubusercontent.com/biolink/biolink-model/v3.0.3/biolink-model.yaml) and did not run into any issues when trying to validate valid_gene object against Entity, NamedThing and Gene.

My example code:

from linkml_validator.validator import Validator

valid_gene = {
    "id": "BOGUS:12345",
    "name": "Bogus Gene 12345",
    "category": ["biolink:NamedThing", "biolink:Gene"],
}

url = "https://raw.githubusercontent.com/biolink/biolink-model/v3.0.3/biolink-model.yaml"
validator = Validator(schema=url)

# Validate against 'Entity' class
res = validator.validate(obj=valid_gene, target_class="Entity")
assert res.valid

# Validate against 'NamedThing' class
res = validator.validate(obj=valid_gene, target_class="NamedThing")
assert res.valid

# Validate against 'Gene' class
res = validator.validate(obj=valid_gene, target_class="Gene")
assert res.valid

Which version of Biolink Model are you using? And was it modified locally in anyway?

glass-ships commented 1 year ago

Thanks @deepakunni3 ! LinkML Validator is @ latest. We were using Biolink Model version: 2.2.16, I just tested again using 3.0.3 with the same result.. Interesting that you don't get the error; even if I copy-paste your example code I get a similar error:

===================================================================================================== ERRORS =====================================================================================================
_________________________________________________________________________________ ERROR collecting tests/unit/test_validation.py _________________________________________________________________________________
tests/unit/test_validation.py:48: in <module>
    assert res.valid
E   assert False
E    +  where False = ValidationReport(object={'id': 'BOGUS:12345', 'name': 'Bogus Gene 12345', 'category': ['biolink:NamedThing', 'biolink:...field=None, value=None, message="Additional properties are not allowed ('category', 'id', 'name' were unexpected)")])]).valid
deepakunni3 commented 1 year ago

@glass-ships Thank you for the follow up and reporting the version of Biolink Model.

After testing in a fresh environment I can reproduce the error you are seeing. And it looks like the bug exists from linkml 1.3.3 onwards.

Will investigate further in the coming days and report back.

deepakunni3 commented 1 year ago

@glass-ships This issue should now be resolved as of Release 0.4.4 (https://pypi.org/project/linkml-validator/0.4.4/)

Let me know if you run into any further issues or feel free to re-open this ticket.