fix: allow restoring content with blank titles#610
Conversation
Restoring a library archive failed whenever any unit (or other container/component) version had a blank title. Blank titles are legal (PublishableEntityVersion.title is blank=True) and common -- content imported from courses via the modulestore migrator frequently has untitled units, and such content can be backed up. The version title round-trips as an empty string, but EntityVersionSerializer.title used CharField(required=True), which defaults to allow_blank=False, so the empty string failed validation and aborted the whole restore. Set allow_blank=True so blank titles validate. The library_backup fixture's unit1 now has a blank title to exercise this path, with a regression test asserting it restores correctly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| Serializer for publishable entity versions. | ||
| """ | ||
| title = serializers.CharField(required=True) | ||
| # We allow_blank because empty unit titles are legal and common. |
There was a problem hiding this comment.
Question for reviewers:
This allows empty titles in all entities. Should we only allow it in Units instead?
There was a problem hiding this comment.
Allow for all. It happens for components as well, especially on older courses.
There was a problem hiding this comment.
Sorry, I wrote that comment in a hurry and I should give more context. We try to force titles for all the components at the editor level these days, because they were being displayed individually by the mobile app (though I think this has since moved back to Unit-level display?). Regardless, for a long while prior to that, some course authors would put titles only at the Unit level, because otherwise it can look goofy from the student view, especially when a Video and HTML block are all on the same topic, and the component title is either directly repeating the Unit title "Intro to Foo" -> "Intro to Foo" or is a useless description like "Video".
Also of note is that whitespace is legal as a title in modulestore, i.e. it is legal to store " " as the display_name, but it gets substituted with the XBlock default display name depending on type. So the field data really is " ", but it's currently displayed as "problem" to the user in the LMS. I think it's okay to strip this whitespace on save, even if that's technically modifying it.
Description
Restoring a library archive failed whenever any unit (or other container/component) version had a blank title. Blank titles are legal (
PublishableEntityVersion.titleisblank=True) and common — content imported from courses via the modulestore migrator frequently has untitled units, and such content can be backed up.The version title round-trips as an empty string, but
EntityVersionSerializer.titleusedCharField(required=True), which defaults toallow_blank=False, so the empty string failed validation and aborted the whole restore. This setsallow_blank=Trueso blank titles validate.The
library_backuptest fixture'sunit1now has a blank title to exercise this path, with a regression test asserting it restores correctly.Related issue
Fixes openedx/openedx-platform#38611
Manual testing instructions
This is the updated library from the test suite:
fixture-library.zip
Restore it on master gives:
Restoring it on this PR's sandbox works (TODO need to verify this once the sandbox is up!)
Other notes
allow_blankonly on entity version titles (units, sections, subsections, components). Learning package and collection titles are unchanged.AI
Generated by Claude Opus 4.8 with this prompt:
I reviewed the code and had it rework the test to be simpler.
Merge deadline
ASAP. We will want to backport this to Verawood before the release, which is probably next week.