linkml / linkml-runtime

Runtime support for linkml generated models
https://linkml.io/linkml/
Creative Commons Zero v1.0 Universal
24 stars 23 forks source link

bug fix in _construct_target_class() #282

Closed RichardBruskiewich closed 11 months ago

RichardBruskiewich commented 11 months ago

The use case in which the input to the patched code is a simple JSON List of (otherwise LinkML-schema compliant) class objects crashes with the code. I noted that the case of a single JSON dictionary object works fine in the line below the patched one (that processes a list of objects).

One notes that BaseModel.parse_obj() appears to only want a dictionary as its argument, not **kwargs from the 'x' dictionary object.

It is suggested that some kind of LinkML defined 'collection' class slot needs be present to constrain data entry. I understand the motivation for that. I suppose there is an argument here that the Model should constraint the presence or absence of "multivalued" inputs.

That said, it seems in fact, However, reading in a simple list of instances of data seems a helpful use case to support by default.

However, this tiny PR patch to the code allows the otherwise correct code to validate and correctly return a JSON List of (LinkML schema class compliant and wrapped) data objects.

codecov[bot] commented 11 months ago

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (b86c1fa) 62.11% compared to head (0be3c4a) 62.09%. Report is 6 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #282 +/- ## ========================================== - Coverage 62.11% 62.09% -0.02% ========================================== Files 63 63 Lines 8459 8461 +2 Branches 2169 2170 +1 ========================================== Hits 5254 5254 Misses 2599 2599 - Partials 606 608 +2 ``` | [Files](https://app.codecov.io/gh/linkml/linkml-runtime/pull/282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linkml) | Coverage Δ | | |---|---|---| | [linkml\_runtime/utils/schema\_as\_dict.py](https://app.codecov.io/gh/linkml/linkml-runtime/pull/282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linkml#diff-bGlua21sX3J1bnRpbWUvdXRpbHMvc2NoZW1hX2FzX2RpY3QucHk=) | `91.30% <100.00%> (ø)` | | | [linkml\_runtime/loaders/loader\_root.py](https://app.codecov.io/gh/linkml/linkml-runtime/pull/282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linkml#diff-bGlua21sX3J1bnRpbWUvbG9hZGVycy9sb2FkZXJfcm9vdC5weQ==) | `69.84% <50.00%> (ø)` | | | [linkml\_runtime/utils/namespaces.py](https://app.codecov.io/gh/linkml/linkml-runtime/pull/282?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linkml#diff-bGlua21sX3J1bnRpbWUvdXRpbHMvbmFtZXNwYWNlcy5weQ==) | `72.51% <43.75%> (-0.86%)` | :arrow_down: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.