Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions xblocks_contrib/annotatable/annotatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ def workbench_scenarios():
),
]

@classmethod
def parse_xml_new_runtime(cls, node, runtime, keys):
"""
Interpret the parsed XML in `node`, creating a new instance of this
module.
"""
# In the new/openedx_content-based runtime, XModule parsing (from
# XmlMixin) is disabled, so definition_from_xml will not be
# called, and instead the "normal" XBlock parse_xml will be used.
# However, it's not compatible with RawMixin, so we implement
# support here.
data_field_value = cls.definition_from_xml(node, None)[0]["data"]
for child in node.getchildren():
node.remove(child)
# Get attributes, if any, via normal parse_xml.
try:
block = super().parse_xml_new_runtime(node, runtime, keys)
except AttributeError:
block = super().parse_xml(node, runtime, keys)
block.data = data_field_value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential crash when importing a bare <annotatable/> node.

definition_from_xml returns {'data': ''} when the node has no children and no attributes (the len == 0 early-exit branch). The assignment here then unconditionally overwrites whatever super().parse_xml set — including the non-empty field default — with an empty string. Any subsequent call to student_view hits etree.fromstring('') in _render_content and raises XMLSyntaxError: Document is empty.

A bare <annotatable/> is an unusual OLX shape, but the guard is cheap:

if data_field_value:
    block.data = data_field_value

This matches how RawMixin handles the equivalent case in edx-platform.

return block

@classmethod
def definition_from_xml(cls, xml_object, system):
if len(xml_object) == 0 and len(list(xml_object.items())) == 0:
Expand Down