Skip to content

Commit d19a698

Browse files
committed
Introduce a check for remote disconnection into the exists() method, since File.exists() in particular sometimes times out.
1 parent 2e2d51a commit d19a698

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fairgraph/kgobject.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from warnings import warn
2626
from typing import Any, Tuple, Dict, List, Optional, TYPE_CHECKING, Union
2727

28-
from requests.exceptions import HTTPError
28+
from requests.exceptions import HTTPError, ConnectionError
2929

3030
try:
3131
from tabulate import tabulate
@@ -589,7 +589,15 @@ def exists(self, client: KGClient, ignore_duplicates: bool = False, in_spaces: O
589589
filters=query_filter,
590590
)
591591

592-
instances = client.query(query=query, size=2, release_status="any", restrict_to_spaces=in_spaces).data
592+
try:
593+
instances = client.query(query=query, size=2, release_status="any", restrict_to_spaces=in_spaces).data
594+
except ConnectionError as err:
595+
if "RemoteDisconnected" in str(err):
596+
warn(
597+
f"Timeout when checking for existence of object {obj}."
598+
"Returning False, check for possible creation of duplicate instances."
599+
)
600+
return False
593601

594602
if instances:
595603
if len(instances) > 1 and not ignore_duplicates:

0 commit comments

Comments
 (0)