Skip to content

fix: truncate discussion topic titles to the column length - #39175

Open
asadali145 wants to merge 1 commit into
openedx:masterfrom
mitodl:asad/truncate-discussion-topic-titles
Open

asadali145 wants to merge 1 commit into
openedx:masterfrom
mitodl:asad/truncate-discussion-topic-titles

Conversation

@asadali145

@asadali145 asadali145 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a course is published, update_course_discussion_config (openedx/core/djangoapps/discussions/handlers.py) refreshes the course's DiscussionTopicLink rows. The topic title comes from course content, and it can be longer than the title column (max_length=255) in two ways:

  1. New or updated unit topics use the unit's display_name. A unit name longer than 255 characters overflows.
  2. Topics for units that are no longer discussable (deleted, unpublished, orphaned, or moved into a timed or proctored exam subsection) get the title "{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 one transaction.atomic(), so that single row rolls back the sync for the entire course. The COURSE_DISCUSSIONS_CHANGED receiver is called through send_robust(), so the error is only logged and the celery task still reports success. The course then stays stuck on every later publish:

  • new units never get discussion topics, so in-context discussions don't show up on them;
  • topics for removed units are never disabled, so the discussions MFE lists them under "Archived";
  • changes to course-wide topics are never applied.

This PR cuts the title to the column's max_length everywhere the sync sets it: the disabled-unit branch, the existing-topic update branch, and the bulk_create of new topics. The limit is read from the model field, so it follows any future column change.

Who is affected:

  • Learners: in-context discussions appear on units again.
  • Course authors: long unit names, or long section, subsection and unit names, no longer silently break discussions for the whole course.
  • Operators: courses already in this state recover on their next publish after this change is deployed.

Supporting information

We found this on a production course. It had been re-imported with a new structure, and two old units' section|subsection|unit titles 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

  1. In a course outline, add a unit whose display name is more than 255 characters long, with discussions enabled. Publish it.
  2. Wait about 30 seconds (COURSE_PUBLISH_TASK_DELAY), then check the CMS worker logs:
    • Before this change: Error calling handle_course_discussion_config_update in Signal.send_robust() ((1406, "Data too long for column 'title' ...")), and no Creating new discussion topic links for <course> line.
    • After this change: Creating new discussion topic links for <course>, with no error.
  3. Open /api/discussion/v2/course_topics/<course_id> as staff, or view the unit in the Learning MFE.
    • Before: the unit has no topic and no discussion sidebar. Any other unit added in the same publish is missing a topic too.
    • After: the unit has a topic whose name is cut to 255 characters, and the in-context discussion sidebar shows on the unit.

2. Removing a unit whose section|subsection|unit title is longer than 255 characters

  1. Create a section, subsection and unit whose names add up to more than 255 characters (for example, about 100 characters each), with discussions enabled on the unit. Publish, and confirm the unit shows up in /api/discussion/v2/course_topics/<course_id>.
  2. Delete that unit, or turn off "Enable discussion" on it. In the same session, add another new unit with discussions enabled. Publish.
  3. Check the CMS worker logs and the course topics API again:
    • Before: the same DataError appears. The new unit gets no topic, and the removed unit's topic stays enabled. In the discussions MFE, it's listed under "Archived".
    • After: the sync completes. The new unit gets a topic, the removed unit's topic is disabled, and its title is the section|subsection|unit string cut to 255 characters.

Deadline

None.

Other information

  • No migrations, no new settings, and no API changes.
  • This change prevents new failures. It also unblocks courses already stuck in this state, without a data fix, the next time they're published.

🤖 Generated with Claude Code

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>
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Oct 1, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @asadali145!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants