|
2 | 2 | Serialize and deserialize OpenAssessment XBlock content to/from XML. |
3 | 3 | """ |
4 | 4 | from uuid import uuid4 as uuid |
| 5 | +import logging |
5 | 6 |
|
6 | 7 | import dateutil.parser |
7 | 8 | import defusedxml.ElementTree as safe_etree |
|
11 | 12 | from openassessment.xblock.data_conversion import update_assessments_format |
12 | 13 |
|
13 | 14 |
|
| 15 | +log = logging.getLogger(__name__) |
| 16 | + |
| 17 | + |
14 | 18 | class UpdateFromXmlError(Exception): |
15 | 19 | """ |
16 | 20 | Error occurred while deserializing the OpenAssessment XBlock content from XML. |
@@ -606,9 +610,21 @@ def serialize_training_examples(examples, assessment_el): |
606 | 610 |
|
607 | 611 | # Answer provided in the example (default to empty string) |
608 | 612 | 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 |
612 | 628 |
|
613 | 629 | # Options selected from the rubric |
614 | 630 | options_selected = example_dict.get('options_selected', []) |
|
0 commit comments