Skip to content

Commit 8807661

Browse files
authored
Merge pull request #1065 from edx/aed/EDUCATOR-1817
EDUCATOR-1817 | be defensive about serializing training examples, log…
2 parents 8c195c0 + 1b8b887 commit 8807661

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

openassessment/xblock/xml.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Serialize and deserialize OpenAssessment XBlock content to/from XML.
33
"""
44
from uuid import uuid4 as uuid
5+
import logging
56

67
import dateutil.parser
78
import defusedxml.ElementTree as safe_etree
@@ -11,6 +12,9 @@
1112
from openassessment.xblock.data_conversion import update_assessments_format
1213

1314

15+
log = logging.getLogger(__name__)
16+
17+
1418
class UpdateFromXmlError(Exception):
1519
"""
1620
Error occurred while deserializing the OpenAssessment XBlock content from XML.
@@ -606,9 +610,21 @@ def serialize_training_examples(examples, assessment_el):
606610

607611
# Answer provided in the example (default to empty string)
608612
answer_el = etree.SubElement(example_el, 'answer')
609-
for part in example_dict.get('answer', {}).get('parts', []):
610-
part_el = etree.SubElement(answer_el, 'part')
611-
part_el.text = unicode(part.get('text', u''))
613+
try:
614+
answer = example_dict.get('answer')
615+
if answer is None:
616+
parts = []
617+
elif isinstance(answer, dict):
618+
parts = answer.get('parts', [])
619+
elif isinstance(answer, list):
620+
parse = answer
621+
622+
for part in example_dict.get('answer', {}).get('parts', []):
623+
part_el = etree.SubElement(answer_el, 'part')
624+
part_el.text = unicode(part.get('text', u''))
625+
except: # excuse the bare-except, looking for more information on EDUCATOR-1817
626+
log.exception('Error parsing training exapmle: %s', example_dict)
627+
raise
612628

613629
# Options selected from the rubric
614630
options_selected = example_dict.get('options_selected', [])

0 commit comments

Comments
 (0)