LeMyst / LeMyst/WikibaseIntegrator

KeyError: 'hash' when parsing Wikidata JSON format references

Closed
#953 2 comments 1 reaction 1 assignee View on GitHub

@LeMyst is already working on this.

Since Mar 12, 2026.

Dominant language
Python
Stars
92
Forks
22
Avg merge
2d 34m
Merged PRs (30d)
10

Description

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:

  1. The format WITH hash field (Wikidata API format)
  2. 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.