diff --git a/onadata/libs/serializers/merged_xform_serializer.py b/onadata/libs/serializers/merged_xform_serializer.py index 8f3717375a..94b527fa2e 100644 --- a/onadata/libs/serializers/merged_xform_serializer.py +++ b/onadata/libs/serializers/merged_xform_serializer.py @@ -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] @@ -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