dahlia / wikidata

Wikidata client library for Python
https://pypi.org/project/Wikidata/
GNU General Public License v3.0
337 stars 31 forks source link

entity.getlist(key) fails for "no value" entries #18

Closed Yorwba closed 5 years ago

Yorwba commented 5 years ago

Example code:

from wikidata.client import Client
client = Client()
hong_kong = client.get('Q8646')
locator_map_image = client.get('P242')
hong_kong.getlist(locator_map_image)

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.6/site-packages/wikidata/entity.py", line 191, in getlist
    for snak in (claim['mainsnak'] for claim in claims)]
  File "/lib/python3.6/site-packages/wikidata/entity.py", line 191, in <listcomp>
    for snak in (claim['mainsnak'] for claim in claims)]
KeyError: 'datavalue'

I believe that this is due to the no value entry in the list for the locator map image of Hong Kong. In this case it appears to be an error in the underlying data, but the function should handle that gracefully. Since the docstring says "Return all values associated to the given key property in sequence.", such no value entries should probably simply get ignored.