fix EditController._ordered_formparams method in case some mandatory relation isn't specified
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 06 Apr 2015 21:49:06 +0200
changeset 10385 cb3a48780615
parent 10383 53d7cf6f0b84
child 10386 82071f767cb8
fix EditController._ordered_formparams method in case some mandatory relation isn't specified If you have an HTML form which doesn't carry information about some mandatory relation (maybe because this relation is set by a hook), you ends up with a KeyError when the form is posted. Using a get instead of subscription protocol fixes the problem. Closes #5481617.
web/views/editcontroller.py
--- a/web/views/editcontroller.py	Wed Jun 03 17:22:06 2015 +0200
+++ b/web/views/editcontroller.py	Mon Apr 06 21:49:06 2015 +0200
@@ -161,7 +161,9 @@
                         # simultaneously edited, the current entity must be
                         # created before the target one
                         if rdef.cardinality[0 if role == 'subject' else 1] == '1':
-                            target_eid = values[param]
+                            # use .get since param may be unspecified (though it will usually lead
+                            # to a validation error later)
+                            target_eid = values.get(param)
                             if target_eid in values_by_eid:
                                 # add dependency from the target entity to the
                                 # current one