[sparql] handle empty result of _sparqlexecute (closes #235720)
authorSamuel Trégouët <samuel.tregouet@logilab.fr>
Thu, 10 Apr 2014 15:05:33 +0200
changeset 428 aed668ce06ea
parent 427 5b87b09238f4
child 429 4aedb4dd72e0
[sparql] handle empty result of _sparqlexecute (closes #235720)
utils/dataio.py
--- a/utils/dataio.py	Thu Apr 24 16:36:57 2014 +0000
+++ b/utils/dataio.py	Thu Apr 10 15:05:33 2014 +0200
@@ -123,9 +123,11 @@
 def sparqlquery(endpoint, query, indexes=None, autocaste_data=True, raise_on_error=False):
     """ Run the sparql query on the given endpoint, and wrap the items in the
     indexes form. If indexes is empty, keep raw output"""
+    results = []
     rawresults = _sparqlexecute(endpoint, query, raise_on_error)
+    if not rawresults:
+        return results
     labels = rawresults['head']['vars']
-    results = []
     indexes = indexes or []
     if autocaste_data:
         transform = autocast
@@ -148,10 +150,12 @@
     """ Execute and format the results of a sparql query.
     Sort the litterals using lang_order.
     """
+    data = {}
     rawresults = _sparqlexecute(endpoint, query, raise_on_error)
+    if not rawresults:
+        return data
     results = rawresults["results"]["bindings"]
     data_lang = {}
-    data = {}
     for row in results:
         for k, v in row.iteritems():
             if v['type'] == 'uri':