jenkins-bot has submitted this change and it was merged. Change subject: T150521: Don't crash on queries with optional values ......................................................................
T150521: Don't crash on queries with optional values The current implementation assumes variables are always set. When using sparql OPTIONAL sometimes values are not set. In that case, set it to None Change-Id: I4af22d4faf42ca1e20581c9dd094237cf3467f71 --- M pywikibot/data/sparql.py 1 file changed, 10 insertions(+), 6 deletions(-) Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py index 70c6563..e95c916 100644 --- a/pywikibot/data/sparql.py +++ b/pywikibot/data/sparql.py @@ -65,13 +65,17 @@ for row in data['results']['bindings']: values = {} for var in qvars: - if full_data: - if row[var]['type'] not in VALUE_TYPES: - raise ValueError('Unknown type: %s' % row[var]['type']) - valtype = VALUE_TYPES[row[var]['type']] - values[var] = valtype(row[var], entity_url=self.entity_url) + if var in row: + if full_data: + if row[var]['type'] not in VALUE_TYPES: + raise ValueError('Unknown type: %s' % row[var]['type']) + valtype = VALUE_TYPES[row[var]['type']] + values[var] = valtype(row[var], entity_url=self.entity_url) + else: + values[var] = row[var]['value'] else: - values[var] = row[var]['value'] + # var is not available (OPTIONAL is probably used) + values[var] = None result.append(values) return result else: -- To view, visit https://gerrit.wikimedia.org/r/322648 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4af22d4faf42ca1e20581c9dd094237cf3467f71 Gerrit-PatchSet: 3 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com> Gerrit-Reviewer: Gerrit Patch Uploader <gerritpatchuploa...@gmail.com> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Magul <tomasz.magul...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: Mpaa <mpaa.w...@gmail.com> Gerrit-Reviewer: Multichill <maar...@mdammers.nl> Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits