archesproject / arches

Arches is a web platform for creating, managing, & visualizing geospatial data. Arches was inspired by the needs of the Cultural Heritage community, particularly the widespread need of organizations to build & manage cultural heritage inventories
GNU Affero General Public License v3.0
212 stars 143 forks source link

ConceptList's from_rdf() should check list vs dict before iterating #4554

Closed azaroth42 closed 5 years ago

azaroth42 commented 5 years ago

Describe the bug

The resolve_node_ids() function iterates through values in its descent through the tree. ConceptList also tries to iterate values, even if there is only one given to it. This results in iterating over a dict's keys, rather than the entries in a list.

To Reproduce

The following JSON-LD is imported:

{
  "@context": "http://localhost:8001/media/linked-art.json",
  "type": "ManMadeObject",
  "label": "Test Object From Import!",
  "identified_by": [
    {
      "classified_as": [
        {
          "id": "http://vocab.getty.edu/aat/300404621", 
          "label": "repository numbers", 
          "type": "Type"
        }
      ], 
      "content": "local-id",
      "type": "Identifier"
     }
  ]
}

Resulting in resolve_node_ids passing this to ConceptListDatatype.from_rdf:

{u'http://www.w3.org/2000/01/rdf-schema#label': [{'@value': u'repository numbers'}], '@id': u'http://vocab.getty.edu/aat/300404621', '@type': [u'http://www.cidoc-crm.org/cidoc-crm/E55_Type']}

Which then proceeds to iterate over the keys, and pass rdfs:label to ConceptDataType.from_rdf.

This fails to work, unsurprisingly.

Proposed Solution

Type check the value coming into ConceptListDatatype to see if it's a list or not:

    def from_rdf(self, json_ld_node):
                # returns a list of concept ids
        ctype = ConceptDataType()
        if isinstance(json_ld_node, list):
            return [ctype.from_rdf(item) for item in json_ld_node]
        else:
            return ctype.from_rdf(json_ld_node)
azaroth42 commented 5 years ago

Fixed in branch, closing.