[view] avoid crush when the relation is optional draft
authorKatia Saurfelt <katia.saurfelt@logilab.fr>
Tue, 22 Sep 2015 11:37:12 +0200
changeset 29 6cf3453bed79
parent 28 de00c758e9ca
[view] avoid crush when the relation is optional closes #6973049
views/formwidgets.py
--- a/views/formwidgets.py	Mon Aug 31 15:07:38 2015 +0200
+++ b/views/formwidgets.py	Tue Sep 22 11:37:12 2015 +0200
@@ -23,7 +23,8 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb import tags
-from cubicweb.web import formwidgets as fwdgs
+from cubicweb.web import (formwidgets as fwdgs,
+                          INTERNAL_FIELD_VALUE)
 
 class TreeViewWidget(fwdgs.FieldWidget):
     """form widget to link to keywords of a given classification"""
@@ -92,7 +93,7 @@
         """filter the rset to only get the root entities"""
         vocab = field.vocabulary(form)
         if vocab:
-            entities = [form._cw.entity_from_eid(i[1]) for i in vocab]
+            entities = [form._cw.entity_from_eid(i[1]) for i in vocab if i[1] != INTERNAL_FIELD_VALUE]
             eids = ', '.join(str(e.eid) for e in entities
                              if e.cw_adapt_to('ITree') and e.cw_adapt_to('ITree').is_root())
             return form._cw.execute('Any X WHERE X eid IN (%(e)s)' % {'e':eids})