fix: support AnnotatableBlock in the new content runtime#268
Conversation
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>
|
Usually it's better to just implement We only introduced |
@bradenmacdonald Thanks for the context — that's really helpful background on why For the extraction work, our focus was largely a lift-and-shift of the existing logic/methods from Current status in xblocks-core: Good point that a single cc: @kdmccormick |
| block = super().parse_xml_new_runtime(node, runtime, keys) | ||
| except AttributeError: | ||
| block = super().parse_xml(node, runtime, keys) | ||
| block.data = data_field_value |
There was a problem hiding this comment.
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_valueThis matches how RawMixin handles the equivalent case in edx-platform.
Closes: openedx/openedx-platform#38809
What
Add a
parse_xml_new_runtimeoverride toAnnotatableBlockso the block can be loaded by the new openedx_content-based content runtime (Content Libraries).Why
While extracting the Annotatable block from
openedx-platform, we parted ways withRawMixin, which contains theparse_xml_new_runtimemethod. That method is still required by the extracted block to be compatible with the new content runtime, and it was missed during extraction.Without it, opening an annotatable block in a Content Library crashes with:
The new runtime loads blocks via
parse_xml_new_runtime. Annotatable only inherited the LegacyXmlMixin fallback, which delegates to the base XBlock.parse_xml. That base parser treats every child XML node as a child block and calls runtime.add_node_as_child(), which the new runtime does not support (it raises the error above). Since annotatable OLX always contains nested markup (<instructions>,<p>,<annotation>), loading always failed.Fix
Copy the parse_xml_new_runtime method from
RawMixinintoAnnotatableBlock. It captures the full inner XML into thedatafield and strips the child nodes before delegating to the base parser.Case study: Problem block (same pattern, already done)
This is exactly how the extracted Problem block was handled:
ProblemBlock(inopenedx-platform) extends RawMixin, inheriting parse_xml_new_runtime.ProblemBlock(here) does not extend RawMixin, and instead explicitly copies parse_xml_new_runtime into its own class.The same was done for the
htmlandvideoblocks. Annotatable was the one raw-data block where this copy was omitted during extraction; this PR brings it in line.Manual testing
NotImplementedErrorin studio logs). After: the component renders.Screenshot
Annotatable Block successfully loaded into the Content Library