Skip to content

Commit eb25877

Browse files
committed
more careful existence checks
1 parent f649f73 commit eb25877

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fairgraph/kgobject.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,19 @@ def exists(self, client: KGClient) -> bool:
514514
client=client,
515515
filters=query_filter,
516516
)
517-
instances = client.query(query=query, size=1, scope="any").data
517+
instances = client.query(query=query, size=2, scope="any").data
518518

519519
if instances:
520+
if len(instances) > 1:
521+
raise Exception("Existence query is not specific enough")
522+
523+
# it seems that sometimes the "query" endpoint returns instances
524+
# which the "instances" endpoint doesn't know about, so here we double check that
525+
# the instance can be found
526+
instance = client.instance_from_full_uri(instances[0]["@id"], scope="any")
527+
if instance is None:
528+
return False
529+
520530
self.id = instances[0]["@id"]
521531
assert isinstance(self.id, str)
522532
save_cache[self.__class__][query_cache_key] = self.id

0 commit comments

Comments
 (0)