Gerrit Patch Uploader has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322648

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, 9 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/48/322648/1

diff --git a/pywikibot/data/sparql.py b/pywikibot/data/sparql.py
index 70c6563..5a47851 100644
--- a/pywikibot/data/sparql.py
+++ b/pywikibot/data/sparql.py
@@ -65,13 +65,16 @@
             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 row.get(var):
+                        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']
+                        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: newchange
Gerrit-Change-Id: I4af22d4faf42ca1e20581c9dd094237cf3467f71
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to