Repository navigation
fix: check the course of searched threads in the database - #303
blarghmatey wants to merge 1 commit into
Conversation
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
|
Thanks for the pull request, @blarghmatey! 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. |
search_threadsloads the threads behind the ids a search index returns. The MySQL query that loads them (handle_threads_query) filtered oncontextbut not oncourse_id, so the course boundary of a search rested entirely on the index's own filter.total_resultswas 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 acourse_idis given. A search without a course (the view passes"") is unchanged. The keys are compared in Python as well as in SQL, because thecourse_idcolumn's collation may compare case-insensitively on MySQL and course keys are case-sensitive.total_resultsnow comes from the query'sthread_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_idsasked for course"course_id"while its threads are incourse123. It only passed because nothing filtered on course, so it now asks forcourse123.Behavior change worth knowing:
total_resultsfeeds edx-platform'sedx.forum.searchedtracking 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: withunread=true,thread_countis taken before the unread pass, so it still includes read threads.Merge checklist:
Check off if complete or not applicable:
Conventional Commits type — they determine the
release:
fix:→ patch,feat:→ minor,!/BREAKING CHANGE:→ majorTesting:
test_search_returns_only_threads_from_the_requested_coursehas the search index return ids from two courses and checks that only the requested course's thread comes back, withtotal_results == 1. It fails on master. The unit suite (347) andtox -e qualitypass locally. To check by hand: create a thread with the same text in two courses, search withcourse_idset to one of them, and confirm only that course's thread is returned and counted.https://claude.ai/code/session_01FGZebDGDTv1ZTtGCEXmxTd