-
Notifications
You must be signed in to change notification settings - Fork 4.2k
reafactor: simplify XModule serialization/deserialization layer [BD-13] #30072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reafactor: simplify XModule serialization/deserialization layer [BD-13] #30072
Conversation
|
Thanks for the pull request, @Agrendalath! When this pull request is ready, tag your edX technical lead. |
e13a20e to
fce06aa
Compare
|
@Agrendalath Just checking what the plan here is. It has been a while. |
|
Author will pick this up soon. |
fce06aa to
b6d4af2
Compare
b6d4af2 to
e196c5c
Compare
9fb07cf to
36b6d86
Compare
5044a04 to
996fe79
Compare
|
@ormsbee, once we wrap up other BD-13 PRs, would you like to review this one too? |
pkulkark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Agrendalath LGTM 👍
- I tested this: Verified that the xblocks are imported, loaded and exported correctly, as per the testing instructions
- I read through the code
-
I checked for accessibility issuesN/A -
Includes documentationN/A
|
@Agrendalath: Yes, I'd like to review this. Just a high level check first: it's intended to keep exactly the same XML serialization that exists today, right (with the exception of the slug stuff which was removed in that other PR)? |
xmodule/x_module.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from an old export_to_xml. Without this change, an XBlock that is not installed is exported as an "unknown" XML tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One edge case that we've had issues with in the past is what happens when you have this scenario:
- Custom XBlock exists. For this example, let's call it a "MusicBlock", with a tag of "music".
- A course with
<music>is imported. - MusicBlock is uninstalled.
- A course with
<music>is exported.
If MusicBlock had never been installed, it goes to the catch-all and the XML is spit out the way it came in. But in this case, it was installed so the original XML was never preserved–it was deserialized into whatever data MusicBlock decided it should be parsed into. In the past, we used to try to look up MusicBlock and fail the export because that code couldn't be found. The fix at one point was to just skip the content that we didn't know how to serialize and let the rest of the course export normally.
I'm not sure what the behavior of this is with the current codebase. If the existing code on master breaks in this scenario today, you don't have to fix it here. But I would like to make sure that this commit doesn't introduce a regression and that if the above scenario works on master today, this commit won't break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ormsbee, thanks for describing this case verbosely.
I compared the behavior on this branch with the master one, and the results were the same for the following scenarios.
Music XBlock (never installed)
- If it has at most
url_namespecified - the import works correctly. - If it contains other attributes than
url_name- the import fails:- XML:
<music url_name="8966c2fbda5e07f9db5ce040d97973842a989d12" display_name="Music" />. - Error:
xblock.plugin.PluginMissingError: music. - User-facing error:
Failed to import module: Music at location: i4x://import/import/music/8966c2fbda5e07f9db5ce040d97973842a989d12(ifdisplay_nameis unspecified, the message displaysNoneinstead ofMusic).
- XML:
Poll XBlock
I did the following points:
- Created an XBlock in Studio.
- Removed the package from
edx-platform. - Exported the course. It produced the following result for this XBlock -
<poll url_name="5424f10c5cf14e2bac9a4a0e2d05d075"/>.
So indeed, the export skips the content of an unknown XBlock.
The catch-all scenario might be tricky to verify now, as it's impossible to import an XBlock with more attributes than url_name (at least without some manual hacks).
|
@ormsbee, that's correct - it should not change any existing serialization/deserialization behaviors (with the exception you've mentioned). |
|
FYI @pdpinch and @Colin-Fredericks: This is a refactoring of how our oldest XBlocks (the XModules implemented in edx-platform) read and write OLX. There is no expected change to output based on tests currently in edx-platform. @Agrendalath: If @pdpinch or @Colin-Fredericks have more advanced validation tests they would like to run, is it possible for them to do so in the sandbox provided with this PR? What are the credentials for that? Thank you. |
Of course - the credentials are |
|
Sorry I missed this. I'll try to take a look next week. I confirmed that I can log into the sandbox. I guess what I want to test is importing some courses with non-standard xBlocks and see how they are modifed in export. Is there any way to test the import management command? I had thought that followed the same code path as a studio import, but we've found some different behaviors in the nutmeg release. |
|
Thanks, @pdpinch.
I can SSH to the sandbox and import them if it works for you. If not, I can look into giving you direct access to this instance. |
|
Sorry for dragging this out so long, but I finally got some time to test today and it seems like the sandbox isn't working. I've tried importing two courses, and now I'm trying to export one of the existing ones from studio. All of them are just spinning. export: stuck on "Exporting: Creating the export data files" To nudge things along a little further, this is the course I'd like to test importing. It contains a custom xBlock that isn't installed on the sandbox. I was hoping to see how that was handled during export. If this isn't going to be a fruitful test, let me know. |
|
@pdpinch, I restarted the workers and the imports are passing now (including the ones that were stuck). These sandbox instances are not always perfectly stable. The test looks fine to me. However, please note that this sandbox has one customization that's not included in this PR - it loads the ErrorBlock when there are errors while importing an XBlock. I can revert it if you'd like to see the standard behavior. |
|
@pdpinch are you able to complete your testing of this now? |
996fe79 to
47248ac
Compare
|
Argh, sorry I missed your comment back in October! My imported course looks good, but I can't export the course from the sandbox again. Reading through Dave's comments more carefully, it seems like I shouldn't expect any different behavior from the export, so I'm not sure it's worth testing. But if you can get the sandbox working again, I'll check (and I promise to look out for notifications) |
Most of the methods in `XmlMixin` act as wrappers for the official API for serialization and deserialization (parse_xml() and add_xml_to_node()). `XmlParserMixin` contains the code which does the actual serialization and deserialization.
It also adds `@XBlock.needs("i18n")` to `XModuleMixin` because this service is
required there.
This removes a `slug` check, as we had already removed its translation in 702866b.
47248ac to
c214e69
Compare
|
@pdpinch, I rebased the PR and re-created the sandbox instance. Could you please import |
|
i was able to import my two test courses without error now. They both include unsupported xBlocks which, as expected, are just dropped on import. I then tested exporting the test courses, which also worked without error. The exported OLX was missing the unrecognized xBlocks. So I think it's working as expected? |
|
@Agrendalath: Nothing else that I can think of. @jristau1984: Please note that while this change has been tested as best as it's practical to do, the support team should immediately flag any new import/export related bugs here. |
|
@Agrendalath By any chance, did you investigate if this change would allow us to get rid of etc. |
|
@bradenmacdonald, thanks for bringing this up. I didn't check this, but verifying it is a good idea, given that we got rid of |
|
@Agrendalath 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
|
EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production. |
|
EdX Release Notice: This PR has been deployed to the production environment. |
|
@bradenmacdonald, I looked into this a bit, but while this change simplifies the parsing, we still need to maintain some legacy code (as we noted in #31108). We could add something like |
|
@Agrendalath Thanks for looking into it! Yeah, it seems like not a big benefit after all, so I don't have a strong opinion on which way to go. If you want to merge your PoC feel free, or I'm totally fine to just leave it. |
|
@bradenmacdonald, I believe that |
Description
Most of the methods in
XmlMixinact as wrappers for the official API for serialization and deserialization (parse_xml()andadd_xml_to_node()).XmlParserMixincontains the code which does the actual serialization and deserialization.This simplifies the serialization layer by:
from_xmldeserialization methods withparse_xml, which is used by XBlocks.XmlMixinclass and renamingXmlParserMixintoXmlMixin. This way, the code handling the serialization and deserialization is retained.XmlDescriptorclass, which was used only in tests.slugfromurl_namelookup, as we had already removed its translation in [BD-13] [BB-5519] refactor: deletes XModuleDescriptorToXBlockMixin #29927.Sandbox
LMS: https://pr30072.sandbox.opencraft.hosting/
Studio: https://studio.pr30072.sandbox.opencraft.hosting/
The sandbox contains one manual change because the Error XBlock is not loaded by default when importing a course. This line is replaced with:
Testing instructions
staffuser.Other information
XmlParserMixin(renamed toXmlMixinnow) and some XBlock classes will continue to retain their custom logic. This logic cannot be removed without breaking backward compatibility. Since this logic does not impact the complexity of the system there are no negatives to retaining it.Private-ref: BB-5573