[web/views] fix editcontroller regression
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 16 Feb 2016 10:52:38 +0100
changeset 11114 468b91aabd9d
parent 11098 7eb9e3e254bc
child 11115 a385bd146178
[web/views] fix editcontroller regression unittest_views_basecontrollers.py's EditControllerTC.test_edit_mandatory_inlined3_object regressed with changeset dcbb64d3a1d9 because it relied on POSTing nonexisting eids. This seems like a silly idea, but let's keep the behaviour unchanged.
web/views/editcontroller.py
--- a/web/views/editcontroller.py	Wed Feb 03 15:12:32 2016 +0100
+++ b/web/views/editcontroller.py	Tue Feb 16 10:52:38 2016 +0100
@@ -27,7 +27,7 @@
 
 from rql.utils import rqlvar_maker
 
-from cubicweb import Binary, ValidationError
+from cubicweb import Binary, ValidationError, UnknownEid
 from cubicweb.view import EntityAdapter
 from cubicweb.predicates import is_instance
 from cubicweb.web import (INTERNAL_FIELD_VALUE, RequestError, NothingToEdit,
@@ -340,8 +340,13 @@
         web/test/unittest_application.py.
         """
         rschema = self._cw.vreg.schema.rschema(field.name)
-        new_value_etypes = set(self._cw.entity_from_eid(eid).cw_etype
-                               for eid in new_values)
+        new_value_etypes = set()
+        # the user could have included nonexisting eids in the POST; don't crash.
+        for eid in new_values:
+            try:
+                new_value_etypes.add(self._cw.entity_from_eid(eid).cw_etype)
+            except UnknownEid:
+                continue
         for unlinked_eid in removed_values:
             unlinked_entity = self._cw.entity_from_eid(unlinked_eid)
             rdef = rschema.role_rdef(form.edited_entity.cw_etype,