Repository navigation
fix: store bare <annotatable/> as OLX, like the built-in block - #324
irfanuddinahmad wants to merge 2 commits into
Conversation
|
Thanks for the pull request, @irfanuddinahmad! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
076fbf2 to
e108e53
Compare
A bare <annotatable/>, which is what Content Libraries v2 creates for a
new Annotatable component, is stored with empty `data` by
definition_from_xml. get_html() and _render_content() then called
etree.fromstring("") and failed with "XMLSyntaxError: Document is
empty", so the library preview returned HTTP 500 until content was
saved. The built-in block rendered such blocks as empty content.
Parse through a helper that treats empty data as an empty
<annotatable/> element.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pointer-tag support in openedx#118 gave Annotatable the EmptyDataRawMixin version of definition_from_xml, which maps a bare <annotatable/> to empty data. The built-in block used RawMixin, which always stores the OLX. With empty data, rendering raised XMLSyntaxError (HTTP 500) and export dropped the block's file while keeping the pointer in its unit. Remove the empty-data branch so a bare element is stored as its OLX. Keep _get_xmltree() so blocks already stored with empty data by earlier releases still render. Add a round-trip test for export. Co-Authored-By: Claude Opus 5.5 <[email protected]>
e108e53 to
a72fdd3
Compare
Description
Fixes #323: an Annotatable whose OLX is a bare
<annotatable/>returns HTTP 500 (XMLSyntaxError: Document is empty), and course export drops its file while keeping the pointer in its unit. Two common ways to get a bare element: creating a new Annotatable in a Content Library V2, and importing a course whose OLX has an empty Annotatable.Root cause. The pointer-tag support in #118 gave Annotatable, LTI and Word Cloud the same
definition_from_xml: the platform'sEmptyDataRawMixinversion, which maps a bare element todata = "". That matches the built-in LTI and Word Cloud blocks, but the built-in Annotatable usedRawMixin, which always stores the OLX. So only Annotatable diverged. Withdata = "",get_html()and_render_content()calletree.fromstring(""), anddefinition_to_xmlreturnsNone, so export skips the block.Changes
definition_from_xml: remove the empty-data branch, so a bare<annotatable/>is stored as its OLX, as in the built-in block. Pointer tags are unaffected:LegacyXmlMixin.load_definition_xmlresolves them beforedefinition_from_xmlruns._get_xmltree(): parsesdata, treating empty or whitespace-only data as an empty<annotatable/>. This only covers blocks that earlier releases already stored withdata = "".Testing
src/xblock_annotatable/tests/test_annotatable.py(13 passed; ruff clean):test_bare_element_from_xml_renders: a bare<annotatable/>renders as<div/>.test_bare_element_round_trips_on_export: a bare<annotatable/>is stored as OLX and exported back.test_get_html_with_empty_data: data already stored as""or whitespace still renders.main. Without the_get_xmltree()fallback, onlytest_get_html_with_empty_datafails.Pointer-tag import → render → export in a local Tutor (platform master, xblocks-core 2.0.0), comparing stock code with this PR:
<annotatable/><annotatable/><annotatable display_name="…"/>display_nameContent Library V2 in the same Tutor stack: create a new Annotatable with
create_library_block, then load and renderstudent_viewthroughopenedx.core.djangoapps.xblock.api(the calls behindGET /api/xblock/v2/xblocks/<usage>/view/student_view/). Run on stock, then this PR, then stock again:<annotatable />XMLSyntaxError<annotatable />data = "<annotatable/>")<annotatable />XMLSyntaxErrorLibraries keep the OLX and re-parse it on every load, so blocks created before this fix render once it's installed.
Context
This blocks openedx/openedx-platform#38746 (removal of the built-in Annotatable block), because the built-in block is currently the only working fallback.
🤖 Generated with Claude Code