Skip to content

Commit 7751c68

Browse files
authored
Merge pull request #89 from SynBioDex/85-fallback_on_lookup_failures
Fix fallback queries
2 parents 412ea5c + 537d0dd commit 7751c68

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

test/test_ontology.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def test_instances(self):
125125
ContO = Ontology(path=test_ontology, uri='https://sift.net/container-ontology/container-ontology')
126126
assert len(ContO['96 well plate'].get_instances()) == 2
127127

128+
def test_fallback(self):
129+
'''Test that fallback to local graph query works when query over network fails.'''
130+
ontobee = SO.endpoints[0]
131+
SO.endpoints = []
132+
self.assertEqual(SO.sequence_feature, 'https://identifiers.org/SO:0000110')
133+
SO.endpoints = [ontobee]
134+
135+
128136
class TestOLS(unittest.TestCase):
129137

130138
SO_endpoints = SO.endpoints

tyto/tyto.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,23 @@ def _handler(self, method_name, exception, *args):
5656
if self.graph and self.graph.is_loaded():
5757
method = getattr(self.graph, method_name)
5858
response = method(self, *args)
59-
if response is not None:
60-
return response
61-
#try:
62-
# response = method(self, *args)
63-
# if response is not None:
64-
# return response
65-
#except Exception as x:
66-
# LOGGER.error(x)
59+
try:
60+
response = method(self, *args)
61+
if response is not None:
62+
return response
63+
except Exception as x:
64+
LOGGER.error(x)
6765

6866
# Try endpoints
6967
if self.endpoints:
7068
for e in self.endpoints:
7169
method = getattr(e, method_name)
72-
response = method(self, *args)
73-
if response is not None:
74-
return response
75-
#try:
76-
# response = method(self, *args)
77-
# if response is not None:
78-
# return response
79-
#except Exception as x:
80-
# LOGGER.error(x)
81-
# raise
70+
try:
71+
response = method(self, *args)
72+
if response is not None:
73+
return response
74+
except Exception as x:
75+
LOGGER.error(x)
8276

8377
# If the connection fails or nothing found, fall back and load the ontology locally
8478
if self.graph and not self.graph.is_loaded():

0 commit comments

Comments
 (0)