Skip to content

Commit

Permalink
Merge pull request #7360 from dimagi/edit-submit-errors
Browse files Browse the repository at this point in the history
fix a bug where editing causing an error lost the original form
  • Loading branch information
sravfeyn committed Jul 8, 2015
2 parents c17f78e + bc807d5 commit 3a614c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions corehq/ex-submodules/couchforms/tests/test_edits.py
Expand Up @@ -189,6 +189,32 @@ def test_case_management(self):
for a in case.actions:
self.assertEqual(form_id, a.xform_id)

def test_second_edit_fails(self):
form_id = uuid.uuid4().hex
case_id = uuid.uuid4().hex
case_block = CaseBlock(
create=True,
case_id=case_id,
case_type='person',
version=V2,
).as_string(format_datetime=json_format_datetime)
submit_case_blocks(case_block, domain=self.domain, form_id=form_id)

# submit an edit form with a bad case update (for example a bad ID)
case_block = CaseBlock(
create=True,
case_id='',
case_type='person',
version=V2,
).as_string(format_datetime=json_format_datetime)
submit_case_blocks(case_block, domain=self.domain, form_id=form_id)

form = XFormInstance.get(form_id)
self.assertEqual('XFormError', form.doc_type)

deprecated_form = XFormInstance.get(form.deprecated_form_id)
self.assertEqual('XFormDeprecated', deprecated_form.doc_type)

def test_case_management_ordering(self):
case_id = uuid.uuid4().hex
owner_id = uuid.uuid4().hex
Expand Down
6 changes: 5 additions & 1 deletion corehq/ex-submodules/couchforms/util.py
Expand Up @@ -496,6 +496,10 @@ def process(xform):
# log the error and respond with a success code so that the phone doesn't
# keep trying to send the form
instance = _handle_known_error(e, instance)
xforms[0] = instance
# this is usually just one document, but if an edit errored we want
# to save the deprecated form as well
XFormInstance.get_db().bulk_save(xforms)
response = self._get_open_rosa_response(instance,
None, None)
return response, instance, cases
Expand Down Expand Up @@ -648,8 +652,8 @@ def _handle_known_error(e, instance):
u"for form {}: {}."
).format(instance._id, error_message))
instance.__class__ = XFormError
instance.doc_type = 'XFormError'
instance.problem = error_message
instance.save()
return instance


Expand Down

0 comments on commit 3a614c9

Please sign in to comment.