Repository navigation
fix: convert OLX and policy values to field types in legacy parse_xml - #362
irfanuddinahmad wants to merge 2 commits into
Conversation
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>
|
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. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
startor another typed field.LegacyXmlMixin.parse_xmlnow converts each OLX andpolicy.jsonvalue with the field'sfrom_jsonbefore setting it, as the platform'sXmlMixinandProblemBlock.parse_xmlalready do.DiscussionXBlock's legacy-format path gets the same one-line fix.Changes
src/xblocks_core/legacy_utils/xml_utils.pysetattr(xblock, name, xblock.fields[name].from_json(value))src/xblock_discussion/block.py_apply_metadata_and_policy. This bug was already in the built-in Discussion block.src/xblocks_core/tests/test_xml_utils.py(new)LegacyXmlMixin.parse_xml, mixed with typed fields like the platform's runtime adds (start,due,graceperiod,visible_to_staff_only). Checks the types and thatsave()works, plus apolicy.jsonoverride.src/xblock_discussion/tests/test_discussion.pytest_legacy_export_format_typed_values: the same check for Discussion'sdiscussion/<url_name>.xmlpath.docs/xblocks_core.rst,docs/xblocks_core.tests.rstxblocks_core.testspackage in the API docs. Thexblocks_corepages are checked in, sosphinx-apidocdoesn't update them, and-Wfails 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 --checkandpylint src/xblocks_core src/xblock_discussionare clean.tox -e docspasses.Live in a local Tutor (platform master, xblocks-core 4.0.0 with these two files on top;
xml_utils.pyis unchanged between 4.0.0 andmain). I imported a unit with one of each of the 8 block types, each withstart="2021-01-01T00:00:00Z", using./manage.py cms import:Unable to load childerrorsstarton each component2021-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