Skip to content

Commit defdeca

Browse files
authored
Merge pull request #114 from apdavison/issue107
Fix KeyError in query() with custom responseVocab
2 parents 5fa6473 + c549487 commit defdeca

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

fairgraph/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def _check_response(
183183
ignore_not_found: bool = False,
184184
error_context: str = "",
185185
expected_instance_id: Optional[str] = None,
186+
id_key: str = "@id",
186187
) -> ResultPage[JsonLdDocument]:
187188
if expected_instance_id and not response.error:
188189
if response.total > 1:
@@ -199,7 +200,7 @@ def _check_response(
199200
response.size = response.total = 0
200201
else:
201202
if response.size == 1:
202-
if str(expected_instance_id) not in response.data[0]["@id"]:
203+
if str(expected_instance_id) not in response.data[0][id_key]:
203204
raise Exception("mismatched instance_id")
204205
if response.error:
205206
# todo: handle "ignore_not_found"
@@ -285,7 +286,7 @@ def _query(release_status, from_index, size):
285286
)
286287
error_context = f"_query(release_status={release_status} query_id={query_id} filter={filter} instance_id={instance_id} size={size} from_index={from_index})"
287288
return self._check_response(
288-
response, error_context=error_context, expected_instance_id=instance_id, ignore_not_found=True
289+
response, error_context=error_context, expected_instance_id=instance_id, id_key=id_key, ignore_not_found=True
289290
)
290291

291292
else:
@@ -303,7 +304,7 @@ def _query(release_status, from_index, size):
303304
)
304305
error_context = f"_query(release_status={release_status} query_id={query_id} filter={filter} instance_id={instance_id} size={size} from_index={from_index})"
305306
return self._check_response(
306-
response, error_context=error_context, expected_instance_id=instance_id, ignore_not_found=True
307+
response, error_context=error_context, expected_instance_id=instance_id, id_key=id_key, ignore_not_found=True
307308
)
308309

309310
if release_status == "any":

0 commit comments

Comments
 (0)