Skip to content

fix: store bare <annotatable/> as OLX, like the built-in block - #324

Open
irfanuddinahmad wants to merge 2 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/annotatable-empty-data
Open

irfanuddinahmad wants to merge 2 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/annotatable-empty-data

Conversation

@irfanuddinahmad

@irfanuddinahmad irfanuddinahmad commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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's EmptyDataRawMixin version, which maps a bare element to data = "". That matches the built-in LTI and Word Cloud blocks, but the built-in Annotatable used RawMixin, which always stores the OLX. So only Annotatable diverged. With data = "", get_html() and _render_content() call etree.fromstring(""), and definition_to_xml returns None, 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_xml resolves them before definition_from_xml runs.
  • _get_xmltree(): parses data, treating empty or whitespace-only data as an empty <annotatable/>. This only covers blocks that earlier releases already stored with data = "".

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.
    • All three fail against main. Without the _get_xmltree() fallback, only test_get_html_with_empty_data fails.
  • Pointer-tag import → render → export in a local Tutor (platform master, xblocks-core 2.0.0), comparing stock code with this PR:

    OLX stock this PR
    pointer → file with content renders, exports identical output
    inline with content renders, exports identical output
    pointer → <annotatable/> 500; file missing from export renders; exports <annotatable/>
    pointer → <annotatable display_name="…"/> 500; file missing from export renders; exports with display_name
  • Content Library V2 in the same Tutor stack: create a new Annotatable with create_library_block, then load and render student_view through openedx.core.djangoapps.xblock.api (the calls behind GET /api/xblock/v2/xblocks/<usage>/view/student_view/). Run on stock, then this PR, then stock again:

    step stored OLX preview
    stock: new block <annotatable /> XMLSyntaxError
    this PR: new block, and the block created on stock <annotatable /> renders (data = "<annotatable/>")
    stock restored: both blocks <annotatable /> XMLSyntaxError

    Libraries 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

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Nov 11, 2026
@openedx-webhooks

openedx-webhooks commented Nov 11, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @irfanuddinahmad!

This repository is currently maintained by @openedx/axim-engineering.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Nov 11, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Nov 16, 2026
@irfanuddinahmad
irfanuddinahmad marked this pull request as ready for review November 23, 2026 06:40
@irfanuddinahmad irfanuddinahmad changed the title fix: render empty Annotatable blocks instead of raising XMLSyntaxError fix: store bare <annotatable/> as OLX, like the built-in block Nov 23, 2026
@irfanuddinahmad
irfanuddinahmad force-pushed the irfanuddinahmad/annotatable-empty-data branch from 076fbf2 to e108e53 Compare November 23, 2026 10:05
irfanuddinahmad and others added 2 commits November 23, 2026 18:37
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]>
@irfanuddinahmad
irfanuddinahmad force-pushed the irfanuddinahmad/annotatable-empty-data branch from e108e53 to a72fdd3 Compare November 23, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

Annotatable: newly created empty block in a Content Library V2 fails to render (XMLSyntaxError: Document is empty)

2 participants