isa-api icon indicating copy to clipboard operation
isa-api copied to clipboard

ISAjson validation not running until the end

Open rabuono opened this issue 3 years ago • 6 comments

Using ISA API v 0.12.2 and Python 3.8.10 When trying to validate an isajson.json file I get the following output:

2021-10-22 09:49:00,414 [INFO]: isajson.py(validate:1406) >> ISA JSON Validator from ISA tools API v0.12. 2021-10-22 09:49:00,414 [INFO]: isajson.py(validate:1415) >> Checking if encoding is UTF8 2021-10-22 09:49:00,426 [INFO]: isajson.py(validate:1417) >> Loading json from isajson/BII-I-1/BII-I-1.json 2021-10-22 09:49:00,493 [INFO]: isajson.py(validate:1419) >> Validating JSON against schemas using Draft4Validator {'errors': [], 'warnings': [], 'validation_finished': True}

However, the validation seems to stop right before the following lines: https://github.com/ISA-tools/isa-api/blob/4f368dee990e88d20484fe0535df1f4f827366d1/isatools/isajson.py#L1420-L1422

If I comment them out, I get a much longer report, indicating the none of the next checks are performed. I have since tried using the more recent isajson.py with the same results.

The behavior is the same with ISAtools example files.

rabuono avatar Oct 22 '21 07:10 rabuono

After some extra digging around, here is an update.

The issue is probably related with me trying to run it on a Windows 10 machine and with how the path for the schemas is provided to RefResolver of jsonschema.

When the same is run on Google Colab or a Linux based machine, a more full version of the isajson validation seems to run.

rabuono avatar Oct 25 '21 14:10 rabuono

@rabuono thx for investigating! Much appreciated as we could not reproduce in our environments (which are unix/linux based)

proccaserra avatar Oct 25 '21 14:10 proccaserra

For what it is worth, the following is able to run the validation from jsonschema on my Windows system.

The trick seems to be in the line: resolver = jsonschema.RefResolver("file:///" + absolute_path_to_base_directory.replace("\\", "/") + "/", schema)

The same chunk of code runs on Google Colab.

I don't know how feasible it is to get the same idea\strategy into isajson.py so that the ISA API validation can be run on a Windows system.

import os
import json
import jsonschema

absolute_path_to_base_directory = os.path.join(r"Users\rabuo\ISA_API\Lib\site-packages\isatools\isa_model_version_1_0_schemas") # "r" otherwise the \r from \rabuo removes the previous directory

#load investigation schema file
with open("isa_model_version_1_0_schemas\investigation_schema.json") as file_object:
    schema = json.load(file_object)

#load json file to be validated
with open('rabuo_handmade_isajson_2.json') as thejson:
    data = json.load(thejson)

#print paths to see if replace leads to expected outcome
print(absolute_path_to_base_directory)
print("file:///" + absolute_path_to_base_directory.replace("\\", "/")) 

resolver = jsonschema.RefResolver("file:///" + absolute_path_to_base_directory.replace("\\", "/") + "/", schema)
jsonschema.Draft4Validator(schema, resolver=resolver).validate(data)

rabuono avatar Oct 25 '21 16:10 rabuono

Using this newer version of isajson.py the validation has the same behavior as described in the beginning of this issue, even in Google Colab. So that got me by surprise. If I again comment out the same as before:

check_isa_schemas(isa_json=isa_json,
                          investigation_schema_path=os.path.join(BASE_DIR, "resources", "schemas", base_schemas_dir,
                                                                 "core", "investigation_schema.json"))  # Rule 0003

This older version of isajson.py seems to work on Google Colab (or at least give a longer output).

rabuono avatar Oct 26 '21 12:10 rabuono

ok thx for reporting @rabuono . Just to be sure, can you provide a release tags or commit numbers you've used when running those tests? much appreciated

proccaserra avatar Oct 26 '21 12:10 proccaserra

The "older version of isajson.py" is ISA API 0.12.2 by installing it through pip install isatools in a Google Colab.

For the "newer version of isajson.py" I just substitute the content of isajson.py installed like above with the one from here. Please let me know if this information is insufficient.

rabuono avatar Oct 26 '21 12:10 rabuono