[web] rql directive breaks if explicit vid and empty rset (closes #1893433) stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Thu, 04 Aug 2011 12:11:36 +0200
branchstable
changeset 7732 5430d0db52ab
parent 7731 48e78934a4e2
child 7733 432e1f0d4857
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
ext/rest.py
ext/test/unittest_rest.py
--- a/ext/rest.py	Wed Aug 03 18:16:02 2011 +0200
+++ b/ext/rest.py	Thu Aug 04 12:11:36 2011 +0200
@@ -105,11 +105,17 @@
     else:
         rql, vid = text, None
     _cw.ensure_ro_rql(rql)
-    rset = _cw.execute(rql, {'userid': _cw.user.eid})
-    if vid is None:
-        vid = vid_from_rset(_cw, rset, _cw.vreg.schema)
-    view = _cw.vreg['views'].select(vid, _cw, rset=rset)
-    content = view.render()
+    try:
+        rset = _cw.execute(rql, {'userid': _cw.user.eid})
+        if rset:
+            if vid is None:
+                vid = vid_from_rset(_cw, rset, _cw.vreg.schema)
+        else:
+            vid = 'noresult'
+        view = _cw.vreg['views'].select(vid, _cw, rset=rset)
+        content = view.render()
+    except Exception, exc:
+        content = 'an error occured while interpreting this rql directive: %r' % exc
     set_classes(options)
     return [nodes.raw('', content, format='html')], []
 
--- a/ext/test/unittest_rest.py	Wed Aug 03 18:16:02 2011 +0200
+++ b/ext/test/unittest_rest.py	Thu Aug 04 12:11:36 2011 +0200
@@ -63,6 +63,16 @@
         self.assert_(out.endswith('<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a>'
                                   '</td></tr></tbody></table></div>\n</div>\n</p>\n'))
 
+    def test_rql_role_with_vid_empty_rset(self):
+        context = self.context()
+        out = rest_publish(context, ':rql:`Any X WHERE X is CWUser, X login "nono":table`')
+        self.assert_(out.endswith('<p><div class="searchMessage"><strong>No result matching query</strong></div>\n</p>\n'))
+
+    def test_rql_role_with_unknown_vid(self):
+        context = self.context()
+        out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:toto`')
+        self.assert_(out.startswith("<p>an error occured while interpreting this rql directive: ObjectNotFound(u'toto',)</p>"))
+
     def test_rql_role_without_vid(self):
         context = self.context()
         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser`')