Skip to content

Commit

Permalink
more careful existence checks
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Jul 25, 2024
1 parent f649f73 commit eb25877
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion fairgraph/kgobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,19 @@ def exists(self, client: KGClient) -> bool:
client=client,
filters=query_filter,
)
instances = client.query(query=query, size=1, scope="any").data
instances = client.query(query=query, size=2, scope="any").data

if instances:
if len(instances) > 1:
raise Exception("Existence query is not specific enough")

# it seems that sometimes the "query" endpoint returns instances
# which the "instances" endpoint doesn't know about, so here we double check that
# the instance can be found
instance = client.instance_from_full_uri(instances[0]["@id"], scope="any")
if instance is None:
return False

self.id = instances[0]["@id"]
assert isinstance(self.id, str)
save_cache[self.__class__][query_cache_key] = self.id
Expand Down

0 comments on commit eb25877

Please sign in to comment.