KGClient.query() accepts an id_key parameter (default "@id") to specify which key identifies the ID in the response JSON-LD documents. This parameter is correctly used in the release_status="any" code path (line 319):
instances[instance[id_key]] = instance
However, _check_response() always hardcodes "@id" when validating the instance_id (line 202):
if str(expected_instance_id) not in response.data[0]["@id"]:
raise Exception("mismatched instance_id")
This means that when a query uses a custom responseVocab that maps @id to a different key (e.g. "id"), calling query() with both instance_id and id_key="id" raises a KeyError: '@id' instead of using the provided id_key.
To reproduce
from fairgraph.client import KGClient
client = KGClient(host="core.kg.ebrains.eu")
# A query whose responseVocab maps @id to "id"
query = {
"@context": {
"@vocab": "https://core.kg.ebrains.eu/vocab/query/",
"query": "https://schema.hbp.eu/myQuery/",
"propertyName": {"@id": "propertyName", "@type": "@id"},
"path": {"@id": "path", "@type": "@id"},
},
"meta": {
"type": "https://openminds.om-i.org/types/DatasetVersion",
"responseVocab": "https://schema.hbp.eu/myQuery/",
},
"structure": [
{"propertyName": "query:id", "path": "@id"},
{"propertyName": "query:fullName", "path": "https://openminds.om-i.org/props/fullName"},
],
}
# Raises KeyError: '@id'
result = client.query(
query=query,
instance_id="07554ebd-95a2-46f0-8065-d961d56ce098",
id_key="id",
release_status="released",
)
Expected behaviour
_check_response() should use the id_key parameter passed to query() instead of hardcoding "@id".
Suggested fix
Thread id_key through to _check_response and use it on line 202:
if str(expected_instance_id) not in response.data[0][id_key]:
Version: 0.13.2
KGClient.query()accepts anid_keyparameter (default"@id") to specify which key identifies the ID in the response JSON-LD documents. This parameter is correctly used in therelease_status="any"code path (line 319):However,
_check_response()always hardcodes"@id"when validating theinstance_id(line 202):This means that when a query uses a custom
responseVocabthat maps@idto a different key (e.g."id"), callingquery()with bothinstance_idandid_key="id"raises aKeyError: '@id'instead of using the providedid_key.To reproduce
Expected behaviour
_check_response()should use theid_keyparameter passed toquery()instead of hardcoding"@id".Suggested fix
Thread
id_keythrough to_check_responseand use it on line 202:Version: 0.13.2