Skip to content

Commit 7ce623d

Browse files
farhanclaude
andauthored
fix: support AnnotatableBlock in the new content runtime (#268)
While extracting the Annotatable block from openedx-platform, we parted ways with RawMixin, which contains the parse_xml_new_runtime method. That method is still required by the extracted annotatable block to make it compatible with the new content runtime, and it was missed during extraction. So this change copies the method from RawMixin into the extracted AnnotatableBlock. Without this, loading an annotatable block in a Content Library crashed with "XML Serialization is only supported with OpenedXContentRuntime", because the base XBlock.parse_xml treats annotatable's nested OLX (<instructions>, <p>, <annotation>) as child blocks and calls runtime.add_node_as_child(), which the new runtime does not implement. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 892fb93 commit 7ce623d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

xblocks_contrib/annotatable/annotatable.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,28 @@ def workbench_scenarios():
246246
),
247247
]
248248

249+
@classmethod
250+
def parse_xml_new_runtime(cls, node, runtime, keys):
251+
"""
252+
Interpret the parsed XML in `node`, creating a new instance of this
253+
module.
254+
"""
255+
# In the new/openedx_content-based runtime, XModule parsing (from
256+
# XmlMixin) is disabled, so definition_from_xml will not be
257+
# called, and instead the "normal" XBlock parse_xml will be used.
258+
# However, it's not compatible with RawMixin, so we implement
259+
# support here.
260+
data_field_value = cls.definition_from_xml(node, None)[0]["data"]
261+
for child in node.getchildren():
262+
node.remove(child)
263+
# Get attributes, if any, via normal parse_xml.
264+
try:
265+
block = super().parse_xml_new_runtime(node, runtime, keys)
266+
except AttributeError:
267+
block = super().parse_xml(node, runtime, keys)
268+
block.data = data_field_value
269+
return block
270+
249271
@classmethod
250272
def definition_from_xml(cls, xml_object, system):
251273
if len(xml_object) == 0 and len(list(xml_object.items())) == 0:

0 commit comments

Comments
 (0)