[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 22 Jan 2015 10:43:24 +0100
changeset 10142 f4a4556f23da
parent 10141 62e1f9749d3a
child 10143 2eb06486273a
[views/forms] Fix EntityFieldsForm.link_to when parent entity is being created When the parent entity is being created and the inlined form is displayed, the parent entity has no eid yet and `peid` is usually 'A'. So int() raises a ValueError. Closes #4627739.
web/test/unittest_views_forms.py
web/views/forms.py
--- a/web/test/unittest_views_forms.py	Sat Jan 03 04:06:06 2015 +0100
+++ b/web/test/unittest_views_forms.py	Thu Jan 22 10:43:24 2015 +0100
@@ -30,6 +30,16 @@
             self.assertEqual({('described_by_test', 'object'): [123]},
                              formview.form.linked_to)
 
+    def test_linked_to_parent_being_created(self):
+        with self.admin_access.web_request() as req:
+            formview = req.vreg['views'].select(
+                'inline-creation', req,
+                etype='File', rtype='described_by_test', role='subject',
+                peid='A',
+                petype='Salesterm')
+            self.assertEqual(formview.form.linked_to, {})
+
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()
--- a/web/views/forms.py	Sat Jan 03 04:06:06 2015 +0100
+++ b/web/views/forms.py	Thu Jan 22 10:43:24 2015 +0100
@@ -400,7 +400,9 @@
         # case where this is an embeded creation form
         try:
             eid = int(self.cw_extra_kwargs['peid'])
-        except KeyError:
+        except (KeyError, ValueError):
+            # When parent is being created, its eid is not numeric (e.g. 'A')
+            # hence ValueError.
             pass
         else:
             ltrtype = self.cw_extra_kwargs['rtype']