I am running this code:
import pywikibot site = pywikibot.Site("wikidata", "wikidata") repo = site.data_repository() item_id = "Q64835" # Özcan Arkoç item = pywikibot.ItemPage(repo, item_id) if item.exists(): print(f"{item_id} exists") else: print(f"{item_id} doesn't exist")
It crashes on item.exists():
Traceback (most recent call last):
File "/home/amir/devel/pywikibot-core/pywikibot/tools/__init__.py", line 771, in wrapper
return getattr(obj, cache_name)
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Claim' object has no attribute '_type'. Did you mean: 'type'?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/amir/devel/pywikibot-core/exists.py", line 8, in <module>
if item.exists():
^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 698, in exists
self.get(get_redirect=True)
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 1165, in get
data = super().get(force, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 737, in get
data = WikibaseEntity.get(self, force=force)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 285, in get
value = cls.fromJSON(self._content.get(key, {}), self.repo)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_collections.py", line 218, in fromJSON
this[key] = [pywikibot.page.Claim.fromJSON(repo, claim)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 1753, in fromJSON
claim.sources.append(cls.referenceFromJSON(site, source))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 1777, in referenceFromJSON
claim = cls.fromJSON(site, {'mainsnak': claimsnak,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 1742, in fromJSON
if claim.type in cls.types:
^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/tools/__init__.py", line 773, in wrapper
val = fn(obj)
^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/page/_wikibase.py", line 1427, in type
return self.repo.getPropertyType(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amir/devel/pywikibot-core/pywikibot/site/_datasite.py", line 278, in getPropertyType
raise KeyError(f'{prop} does not exist')
KeyError: "Claim(DataSite('wikidata', 'wikidata'), 'P6615') does not exist"
CRITICAL: Exiting due to uncaught exception KeyError: "Claim(DataSite('wikidata', 'wikidata'), 'P6615') does not exist"The same code outputs "Q64834 exists", "Q64836 exists", and "Q7 doesn't exist" when running with these Q numbers, but Q64835 causes it to crash.
Maybe it happens because property 6615, which was used in a statement on that item, was deleted a couple of months ago. The statement was deleted, too, and it's not even the latest edit on the item. In any case, such a thing probably shouldn't cause the whole script to crash.