Skip to content

fix: report endorsed status for threads in MySQL thread lists - #292

Merged
taimoor-ahmed-1 merged 1 commit into
openedx:masterfrom
AhtishamShahid:ahtisham/fix-mysql-thread-list-endorsed
Sep 30, 2026
Merged

taimoor-ahmed-1 merged 1 commit into
openedx:masterfrom
AhtishamShahid:ahtisham/fix-mysql-thread-list-endorsed

Conversation

@AhtishamShahid

Copy link
Copy Markdown
Contributor

Description

With the MySQL backend, a question with an endorsed ("answered") response is always listed as unanswered.

MySQLBackend.get_endorsed() returns a dict keyed by str(thread_id):

return {str(thread_id): True for thread_id in endorsed_thread_ids}

threads_presentor() looked that dict up with the integer primary key, so the lookup always missed and every thread came back with endorsed: False:

is_endorsed = threads_endorsed.get(thread.pk, False)  # 5 != "5"

This PR looks the thread up by str(thread.pk), which matches the read_states and threads_flagged lookups next to it. The MongoDB backend is not affected because it uses string ids on both sides.

User-facing impact

In the discussions MFE, marking a response as the answer shows the green "answered" checkmark in the post list. That's because the MFE re-fetches the single thread, which does not go through threads_presentor. After a page reload, the list is rebuilt from the thread-list endpoint, which returned has_endorsed: false, so the checkmark disappeared. Course staff then had no way to see at a glance which questions still needed an answer.

Testing

  • Added test_threads_presentor_includes_endorsed_status. It fails on master and passes with this change.
  • Full unit suite passes (pytest --ignore=tests/e2e: 203 passed). pylint and mypy are clean. isort is clean on the changed files.

Manual testing instructions

  1. In an Open edX (Tutor) dev environment, enable forum_v2.enable_mysql_backend for a course.
  2. In the discussions MFE, as course staff, create a question post and add a response.
  3. Mark the response as the answer. The green checkmark appears in the post list.
  4. Reload the page.
    • Before this change: the checkmark disappears, and GET /api/discussion/v1/threads/?course_id=... returns "has_endorsed": false for the thread.
    • After this change: the checkmark stays, and the list returns "has_endorsed": true.

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added (N/A, the repo has no changelog)
  • Documentation updated (not only docstrings) (N/A)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets (no migrations or new dependencies)

MySQLBackend.get_endorsed() returns a dict keyed by the thread id as a
string, but threads_presentor() looked it up with the integer primary
key, so every thread in a list was reported as unendorsed. Answered
questions therefore lost their "answered" state in the discussions
sidebar after a page reload, while the single-thread endpoint (which
does not go through threads_presentor) kept reporting them correctly.

Look the thread up by str(thread.pk), matching the read state and abuse
flag lookups next to it.
Copilot AI balanced review requested due to automatic review settings September 29, 2026 10:27
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @AhtishamShahid!

This repository is currently maintained by @openedx/wg-maintainers-forums.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fix aligns ID types and is adequately covered by a regression test.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes MySQL thread lists to preserve answered/endorsed status after reload.

Changes:

  • Uses string thread IDs for endorsed-status lookup.
  • Adds regression coverage for answered and unanswered threads.
File Description
src/​forum/​backends/​mysql/​api.py Corrects endorsed-status lookup key type.
tests/​test_backends/​test_mysql/​test_api.py Adds regression test for endorsement presentation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@AhtishamShahid

Copy link
Copy Markdown
Contributor Author

Hi , @taimoor-ahmed-1 can you please merge this PR? I don't have write access to this repo. Thanks.

@taimoor-ahmed-1
taimoor-ahmed-1 merged commit b098f80 into openedx:master Sep 30, 2026
11 checks passed
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: Done

Development

Successfully merging this pull request may close these issues.

4 participants