Skip to content

fix: convert OLX and policy values to field types in legacy parse_xml - #362

Open
irfanuddinahmad wants to merge 2 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/legacy-xml-from-json
Open

irfanuddinahmad wants to merge 2 commits into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/legacy-xml-from-json

Conversation

@irfanuddinahmad

@irfanuddinahmad irfanuddinahmad commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Course import drops components whose OLX sets start (or other typed fields) #361: a course import silently drops HTML, Poll, Word Cloud, Annotatable, LTI and Discussion components whose OLX sets start or another typed field.
  • LegacyXmlMixin.parse_xml now converts each OLX and policy.json value with the field's from_json before setting it, as the platform's XmlMixin and ProblemBlock.parse_xml already do. DiscussionXBlock's legacy-format path gets the same one-line fix.

Why it matters: this affects platform master today. Video, HTML, Discussion and Word Cloud no longer have a built-in fallback (openedx/openedx-platform#37819).

Changes

File Change
src/xblocks_core/legacy_utils/xml_utils.py setattr(xblock, name, xblock.fields[name].from_json(value))
src/xblock_discussion/block.py The same in _apply_metadata_and_policy. This bug was already in the built-in Discussion block.
src/xblocks_core/tests/test_xml_utils.py (new) Parses OLX for each of the 5 blocks that use LegacyXmlMixin.parse_xml, mixed with typed fields like the platform's runtime adds (start, due, graceperiod, visible_to_staff_only). Checks the types and that save() works, plus a policy.json override.
src/xblock_discussion/tests/test_discussion.py test_legacy_export_format_typed_values: the same check for Discussion's discussion/<url_name>.xml path.
docs/xblocks_core.rst, docs/xblocks_core.tests.rst List the new xblocks_core.tests package in the API docs. The xblocks_core pages are checked in, so sphinx-apidoc doesn't update them, and -W fails on an orphan page.

Test plan

  • All 7 new tests fail on main (assert '2021-01-01T00:00:00Z' == datetime(...)) and pass here.

  • pytest src: 871 passed. ruff check, ruff format --check and pylint src/xblocks_core src/xblock_discussion are clean. tox -e docs passes.

  • Live in a local Tutor (platform master, xblocks-core 4.0.0 with these two files on top; xml_utils.py is unchanged between 4.0.0 and main). I imported a unit with one of each of the 8 block types, each with start="2021-01-01T00:00:00Z", using ./manage.py cms import:

    Stock 4.0.0 This PR
    Unable to load child errors 6 0
    Components in the unit 2 (problem, video) 8
    start on each component — 2021-01-01 00:00:00+00:00 (a datetime)

Closes #361. Part of the Slash-n-Burn Built-In XBlocks epic.

🤖 Generated with Claude Code

LegacyXmlMixin.parse_xml and DiscussionXBlock's legacy-format path set
fields to the raw strings from OLX attributes and policy.json. For typed
fields such as `start` (a Date), saving the block then raised
"TypeError: Cannot convert '...' to json", and a course import dropped
the component ("Unable to load child when parsing Vertical").

Convert each value with the field's from_json, as the platform's
XmlMixin and ProblemBlock.parse_xml already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 Dec 4, 2026
@openedx-webhooks

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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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: Needs Triage

Development

Successfully merging this pull request may close these issues.

Course import drops components whose OLX sets start (or other typed fields)

2 participants