diff --git a/opentech/apply/funds/models/mixins.py b/opentech/apply/funds/models/mixins.py index 5ddbb637742cfe69d6d4ecef7028b9e037c422d5..87a1dd39ea31e63666f76fac46e9071fa3dd6d88 100644 --- a/opentech/apply/funds/models/mixins.py +++ b/opentech/apply/funds/models/mixins.py @@ -36,8 +36,13 @@ class AccessFormData: data = self.form_data.copy() for field_name, field_id in self.named_blocks.items(): if field_id not in data: - response = data[field_name] - data[field_id] = response + try: + response = data[field_name] + except KeyError: + # There was no value supplied for the named field + pass + else: + data[field_id] = response return data @classmethod diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py index 0745ef0280d4c152d7f9147fe5c6f6f8a3e22a87..5943d8b769d890264a5198dfe793c1e1a7832922 100644 --- a/opentech/apply/funds/tests/test_models.py +++ b/opentech/apply/funds/tests/test_models.py @@ -468,6 +468,13 @@ class TestSubmissionRenderMethods(TestCase): answers = submission.render_answers() self.assertNotIn(rich_text_label, answers) + def test_named_blocks_dont_break_if_no_response(self): + submission = ApplicationSubmissionFactory() + # the user didn't respond + del submission.form_data['value'] + self.assertTrue('value' not in submission.raw_data) + self.assertTrue('duration' in submission.raw_data) + class TestRequestForPartners(TestCase): def test_message_when_no_round(self):