Skip to content

fix: check the course of searched threads in the database - #303

Open
blarghmatey wants to merge 1 commit into
openedx:masterfrom
mitodl:tmacey/search-course-boundary
Open

blarghmatey wants to merge 1 commit into
openedx:masterfrom
mitodl:tmacey/search-course-boundary

Conversation

@blarghmatey

Copy link
Copy Markdown
Contributor

search_threads loads the threads behind the ids a search index returns. The MySQL query that loads them (handle_threads_query) filtered on context but not on course_id, so the course boundary of a search rested entirely on the index's own filter. total_results was the index's raw hit count, before the database applied the course, group, author or other filters.

This adds a course check to handle_threads_query, applied whenever a course_id is given. A search without a course (the view passes "") is unchanged. The keys are compared in Python as well as in SQL, because the course_id column's collation may compare case-insensitively on MySQL and course keys are case-sensitive. total_results now comes from the query's thread_count.

The other callers already pass ids from the same course: user active threads, plus user threads and subscriptions through get_threads. So the check only changes their results if a comment's course ever differed from its thread's.

test_filter_by_commentable_ids asked for course "course_id" while its threads are in course123. It only passed because nothing filtered on course, so it now asks for course123.

Behavior change worth knowing: total_results feeds edx-platform's edx.forum.searched tracking event and a log line. It now reflects the filters a search applies, so it can be lower than before for the same query. One exception: with unread=true, thread_count is taken before the unread pass, so it still includes read threads.

Merge checklist:
Check off if complete or not applicable:

  • Commit messages (and PR title, if squash merging) use the correct
    Conventional Commits type — they determine the
    release: fix: → patch, feat: → minor, ! / BREAKING CHANGE: → major
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

Testing: test_search_returns_only_threads_from_the_requested_course has the search index return ids from two courses and checks that only the requested course's thread comes back, with total_results == 1. It fails on master. The unit suite (347) and tox -e quality pass locally. To check by hand: create a thread with the same text in two courses, search with course_id set to one of them, and confirm only that course's thread is returned and counted.

https://claude.ai/code/session_01FGZebDGDTv1ZTtGCEXmxTd

search_threads loads the threads behind the ids a search index returns,
and the MySQL query that loads them filtered on context but not on
course, so the course boundary rested entirely on the index's own
filter. handle_threads_query now keeps only threads whose course_id
equals the requested one, comparing the keys in Python as well because
the column's collation may be case-insensitive. total_results now
counts what that query kept instead of the index's raw hits.

test_filter_by_commentable_ids queried a course its threads were not
in, which only passed because nothing filtered on course.

Claude-Session: https://claude.ai/code/session_01FGZebDGDTv1ZTtGCEXmxTd
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 1, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @blarghmatey!

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Dec 1, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Dec 2, 2026
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: Ready for Review

Development

Successfully merging this pull request may close these issues.

2 participants