diff --git a/src/linkahead/apiutils.py b/src/linkahead/apiutils.py index 31e49aa9a25ea8a58a0cdf2b5e81f6c489a36b5f..1504db8e482e31768fdda09017a2b515fe0f3434 100644 --- a/src/linkahead/apiutils.py +++ b/src/linkahead/apiutils.py @@ -377,15 +377,18 @@ def compare_entities(entity0: Optional[Entity] = None, # compare properties for prop in entity0.properties: - matching = entity1.properties.filter(name=prop.name, pid=prop.id) + key = prop.name if prop.name else prop.id # ToDo: Would making id default break anything? + matching = entity1.properties.filter(prop) if len(matching) == 0: # entity1 has prop, entity0 does not - diff[0]["properties"][prop.name] = {} + diff[0]["properties"][key] = {} elif len(matching) == 1: - diff[0]["properties"][prop.name] = {} - diff[1]["properties"][prop.name] = {} - propdiff = (diff[0]["properties"][prop.name], - diff[1]["properties"][prop.name]) + # It's possible that prop has name and id, but match only has id + key = prop.name if prop.name and matching[0].name else prop.id + diff[0]["properties"][key] = {} + diff[1]["properties"][key] = {} + propdiff = (diff[0]["properties"][key], + diff[1]["properties"][key]) # We should compare the wrapped properties instead of the # wrapping entities if possible: @@ -417,8 +420,8 @@ def compare_entities(entity0: Optional[Entity] = None, # in case there is no difference, we remove the dict keys again if len(propdiff[0]) == 0 and len(propdiff[1]) == 0: - diff[0]["properties"].pop(prop.name) - diff[1]["properties"].pop(prop.name) + diff[0]["properties"].pop(key) + diff[1]["properties"].pop(key) else: raise NotImplementedError( @@ -426,11 +429,12 @@ def compare_entities(entity0: Optional[Entity] = None, # we have not yet compared properties that do not exist in entity0 for prop in entity1.properties: + key = prop.name if prop.name else prop.id # ToDo: Would making id default break anything? # check how often the property appears in entity0 num_prop_in_ent0 = len(entity0.properties.filter(prop)) if num_prop_in_ent0 == 0: # property is only present in entity0 - add to diff - diff[1]["properties"][prop.name] = {} + diff[1]["properties"][key] = {} if num_prop_in_ent0 > 1: # Check whether the property is present multiple times in entity0 # and raise error - result would be incorrect @@ -441,9 +445,10 @@ def compare_entities(entity0: Optional[Entity] = None, for index, parents, other_entity in [(0, entity0.parents, entity1), (1, entity1.parents, entity0)]: for parent in parents: + key = parent.name if parent.name else parent.id # ToDo: Would making id default break anything? matching = other_entity.parents.filter(parent) if len(matching) == 0: - diff[index]["parents"].append(parent.name) + diff[index]["parents"].append(key) continue return diff