Skip to content

Commit

Permalink
Raise ValidationError on PyXFormError exceptions
Browse files Browse the repository at this point in the history
This should allow the user to see what the problem with the merged form
is.
  • Loading branch information
ukanga committed Aug 16, 2018
1 parent a5b4303 commit 8dfd8d1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion onadata/libs/serializers/merged_xform_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from onadata.apps.logger.models.xform import XFORM_TITLE_LENGTH
from onadata.libs.utils.common_tags import MULTIPLE_SELECT_TYPE, SELECT_ONE
from pyxform.builder import create_survey_element_from_dict
from pyxform.errors import PyXFormError

SELECTS = [SELECT_ONE, MULTIPLE_SELECT_TYPE]

Expand Down Expand Up @@ -179,7 +180,11 @@ def create(self, validated_data):
survey['sms_keyword'] = survey['id_string']
survey['title'] = validated_data.pop('name')
validated_data['json'] = survey.to_json()
validated_data['xml'] = survey.to_xml()
try:
validated_data['xml'] = survey.to_xml()
except PyXFormError as error:
raise serializers.ValidationError(_(
"Problem Merging the Form: {}".format(error)))
validated_data['user'] = validated_data['project'].user
validated_data['created_by'] = request.user
validated_data['is_merged_dataset'] = True
Expand Down

0 comments on commit 8dfd8d1

Please sign in to comment.