jenkins-bot submitted this change.
[wikibase] give a more informative exception
Give a more informative exception if a property does not exists instead
of just KeyError: <prop>
Bug: T368908
Change-Id: I53d95f413d535947dc0d3fd4b753c095dd653c9b
---
M pywikibot/site/_datasite.py
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index a61773d..f5be91e 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -1,6 +1,6 @@
"""Objects representing API interface to Wikibase site."""
#
-# (C) Pywikibot team, 2012-2023
+# (C) Pywikibot team, 2012-2024
#
# Distributed under the terms of the MIT license.
#
@@ -253,11 +253,12 @@
yield page
def getPropertyType(self, prop):
- """
- Obtain the type of a property.
+ """Obtain the type of a property.
- This is used specifically because we can cache
- the value for a much longer time (near infinite).
+ This is used specifically because we can cache the value for a
+ much longer time (near infinite).
+
+ :raises KeyError: *prop* does not exist
"""
params = {'action': 'wbgetentities', 'ids': prop.getID(),
'props': 'datatype'}
@@ -269,11 +270,14 @@
# the IDs returned from the API can be upper or lowercase, depending
# on the version. See bug T55894 for more information.
try:
- dtype = data['entities'][prop.getID()]['datatype']
+ entity = data['entities'][prop.getID()]
except KeyError:
- dtype = data['entities'][prop.getID().lower()]['datatype']
+ entity = data['entities'][prop.getID().lower()]
- return dtype
+ if 'missing' in entity:
+ raise KeyError(f'{prop} does not exist')
+
+ return entity['datatype']
@need_right('edit')
def editEntity(self, entity, data, bot: bool = True, **kwargs):
To view, visit change 1051096. To unsubscribe, or for help writing mail filters, visit settings.