linkml / linkml

Linked Open Data Modeling Language
https://linkml.io/linkml
Other
298 stars 90 forks source link

Prefix with hyphenated name won't validate JSON #807

Closed galund closed 3 months ago

galund commented 2 years ago

Describe the bug (This bug is similar but not the same as https://github.com/linkml/linkml/issues/757.)

A prefix with a hyphenated name causes a NameError when compiling to Python in order to validate some JSON.

To Reproduce

  1. Create a very basic schema with a hyphenated prefix, such as:
id: https://example.com/test
name: test-schema
prefixes:
  linkml: https://w3id.org/linkml/
  some-prefix: https://example.com/test1-prefix-name
imports:
  - linkml:types
default_prefix: some-prefix
classes:
  TestClass:
    attributes:
      testProperty:
  1. Attempt to validate from JSON against that schema eg by running linkml-validate -s linkml-schemas/basic.yml examples/test.json

Expected behavior Validation should proceed as if some-prefix in the example above were replaced with someprefix.

Actual behavior

  File "[...]/lib/python3.10/site-packages/linkml_runtime/utils/compile_python.py", line 47, in compile_python
    exec(spec, module.__dict__)
  File "test", line 36, in <module>
NameError: name 'SOME' is not defined

Additional context Add any other context about the problem here.

cmungall commented 2 years ago

Thanks for the report!

As an interim measure until we resolve #757 we will implement an option in linkml-validate to bypass instantiating python objects, and pass the dictionary directly to validation

This will be useful anyway, because the python instantiation automatically repairs certain kinds of structural issues - for example if you pass a single value to a multivalued field, it will fix this. This can be handy, but this is not always desirable

matentzn commented 2 years ago

Yeah, just about the report the same.

sierra-moxon commented 1 year ago

@ialarmedalien Keeping this ticket open as a stand-in for #897

sujaypatil96 commented 1 year ago

Dupe of #1157

sujaypatil96 commented 1 year ago

@sierra-moxon / @sujaypatil96 / @nlharris: investigate issue fix and assign priority

sierra-moxon commented 3 months ago

ran again, fixed.