ResearchObject / ro-crate-py

Python library for RO-Crate
https://pypi.org/project/rocrate/
Apache License 2.0
46 stars 23 forks source link

hasPart property on root dataset is assumed to be an array #158

Closed ptsefton closed 11 months ago

ptsefton commented 1 year ago

Loading this dataset causes an error as the hasPart value is not an array but the code assumes it will be :

{
    "@id": "./",
    "@type": "Dataset",
    "hasPart":  {"@id": "spam/foo.txt"} 
},
{
    "@id": "spam/foo.txt",
    "@type": "File"
}

This line is the culprit: https://github.com/ResearchObject/ro-crate-py/blob/dc3f75b0d0390dedbf9a830b6325b76dba468f1f/rocrate/rocrate.py#L145C1-L146C1

parts = root_entity.pop('hasPart', [])

I added this to my copy make it work but not sure if you have a general purpose way of doing this in this library:

    if not isinstance(parts, list):
        parts = [parts]