When passing claims in the standard Wikidata JSON format (as returned by the Wikidata API) to References().from_json(), it fails with KeyError: 'hash'.
Steps to reproduce:
from wikibaseintegrator.models.references import Reference, References
Wikidata format includes 'hash' field in references
wikidata_claims = {
"P31": [{
"mainsnak": {...},
"type": "statement",
"id": "Q42$123",
"rank": "normal",
"references": [{
"hash": "abc123def456",
"snaks": {...}
}]
}]
}
This fails:
References().from_json(wikidata_claims["P31"][0]["references"])
Error traceback:
File "/usr/local/lib/python3.13/site-packages/wikibaseintegrator/models/references.py", line 57, in from_json
self.add(reference=Reference().from_json(reference))
File "/usr/local/lib/python3.13/site-packages/wikibaseintegrator/models/references.py", line 136, in from_json
self.hash = json_data['hash']
KeyError: 'hash'
Expected behavior:
The library should handle both:
- The format WITH hash field (Wikidata API format)
- The format WITHOUT hash field (when creating new references)
Environment:
- wikibaseintegrator version: 0.12.15
- Python 3.13
Additional context:
This affects anyone trying to import entities from Wikidata JSON format to a Wikibase instance using this library for validation.
the file I tried to import in Entitybase is here https://github.com/dpriskorn/entitybase-import/blob/master/test_data/test1.jsonl line 1
When passing claims in the standard Wikidata JSON format (as returned by the Wikidata API) to References().from_json(), it fails with KeyError: 'hash'.
Steps to reproduce:
from wikibaseintegrator.models.references import Reference, References
Wikidata format includes 'hash' field in references
This fails:
Expected behavior:
The library should handle both:
Environment:
Additional context:
This affects anyone trying to import entities from Wikidata JSON format to a Wikibase instance using this library for validation.
the file I tried to import in Entitybase is here https://github.com/dpriskorn/entitybase-import/blob/master/test_data/test1.jsonl line 1