indico
indico copied to clipboard
Improved error handling to gracefully manage invalid inputs
trafficstars
FWIW this is the error I get when sending {"field_825794":{"lol":69}} as the payload to update a registration:
File "/home/adrian/dev/indico/py3/src/indico/modules/events/registration/util.py", line 487, in modify_registration
new_data = snapshot_registration_data(registration)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adrian/dev/indico/py3/src/indico/modules/events/registration/util.py", line 951, in snapshot_registration_data
'friendly_data': regdata.friendly_data}
^^^^^^^^^^^^^^^^^^^^^
File "/home/adrian/dev/indico/py3/src/indico/modules/events/registration/models/registrations.py", line 829, in friendly_data
return self.get_friendly_data()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adrian/dev/indico/py3/src/indico/modules/events/registration/models/registrations.py", line 836, in get_friendly_data
return self.field_data.field.get_friendly_data(self, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adrian/dev/indico/py3/src/indico/modules/events/registration/models/form_fields.py", line 100, in get_friendly_data
return self.field_impl.get_friendly_data(registration_data, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adrian/dev/indico/py3/src/indico/modules/events/registration/fields/choices.py", line 237, in get_friendly_data
caption = registration_data.field_data.field.data['captions'][uuid]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'lol'
So there are indeed cases that need to be fixed. In fact, we should probably fail validation earlier when there's data that's not a valid choice (careful so it still works in case of a multiselect field where one of the already-selected choices has been removed, since you can still have and keep it in an existing registration).