fix: truncate discussion topic titles to the column length - #39175
asadali145 wants to merge 1 commit into
Conversation
Discussion topic titles come from course content: a unit's display name, or "section|subsection|unit" when a unit is no longer discussable. Either can exceed DiscussionTopicLink.title's 255-character limit. On strict MySQL that raises a DataError, and because the sync runs in a single transaction (and the error is swallowed by send_robust), one oversized title silently blocks the entire course's topic sync: new units get no topics and removed units are never disabled. Truncate the title wherever the sync sets it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Thanks for the pull request, @asadali145! 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. |
Description
When a course is published,
update_course_discussion_config(openedx/core/djangoapps/discussions/handlers.py) refreshes the course'sDiscussionTopicLinkrows. The topic title comes from course content, and it can be longer than thetitlecolumn (max_length=255) in two ways:display_name. A unit name longer than 255 characters overflows."{section}|{subsection}|{unit}", rebuilt from the stored context. Three ordinary-length names can easily add up to more than 255 characters.On MySQL in strict mode (the default in MySQL 8), saving an oversized title raises
DataError (1406, "Data too long for column 'title'"). The whole update runs inside onetransaction.atomic(), so that single row rolls back the sync for the entire course. TheCOURSE_DISCUSSIONS_CHANGEDreceiver is called throughsend_robust(), so the error is only logged and the celery task still reports success. The course then stays stuck on every later publish:This PR cuts the title to the column's
max_lengtheverywhere the sync sets it: the disabled-unit branch, the existing-topic update branch, and thebulk_createof new topics. The limit is read from the model field, so it follows any future column change.Who is affected:
Supporting information
We found this on a production course. It had been re-imported with a new structure, and two old units'
section|subsection|unittitles were 257 and 282 characters long. Every discussion sync for the course had failed for about three weeks. Its 204 current units had no discussion topics, and all of the old units' topics showed up as "Archived".Testing instructions
Use an environment backed by MySQL 8 (for example, Tutor). In Studio, make sure the course uses the Open edX discussion provider with unit-level discussions enabled (Pages & Resources → Discussion).
1. A unit display name longer than 255 characters
COURSE_PUBLISH_TASK_DELAY), then check the CMS worker logs:Error calling handle_course_discussion_config_update in Signal.send_robust() ((1406, "Data too long for column 'title' ...")), and noCreating new discussion topic links for <course>line.Creating new discussion topic links for <course>, with no error./api/discussion/v2/course_topics/<course_id>as staff, or view the unit in the Learning MFE.2. Removing a unit whose
section|subsection|unittitle is longer than 255 characters/api/discussion/v2/course_topics/<course_id>.DataErrorappears. The new unit gets no topic, and the removed unit's topic stays enabled. In the discussions MFE, it's listed under "Archived".section|subsection|unitstring cut to 255 characters.Deadline
None.
Other information
🤖 Generated with Claude Code