Discussion API: missing thread returns 500 (ForumV2RequestError not mapped to ThreadNotFoundError)

Đang mở Phù hợp với người mới
#39,225 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mbhavu2007-lang đang làm issue này rồi.

Từ ngày 31/10/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
mysql, python
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu từ lms/djangoapps/discussion/rest_api/api.py tại _get_thread_and_context và _get_comment_and_context, hai hàm này bắt CommentClientRequestError khi một thread hoặc comment bị thiếu. Lời gọi bị lỗi là Thread._retrieve trong comment_client/thread.py, hàm này gọi forum.api.get_thread và để forum.utils.ForumV2RequestError lan ra ngoài. Bạn có thể chuyển lỗi đó thành CommentClientRequestError trong comment client, hoặc bắt nó ngay trong các mệnh đề except của những hàm đó. Hoàn thành khi DELETE, GET hoặc PATCH trên một thread bị thiếu trả về 404 thay vì 500, và có một test bao phủ trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

With the forum v2 backend (openedx/forum, used in-process), DELETE /api/discussion/v1/threads/<id>/ for a thread that no longer exists returns a bare 500, not 404:

forum.utils.ForumV2RequestError: Thread does not exist with Id: 137
  File ".../forum/api/threads.py", line 141, in get_thread
  File ".../forum/backends/mysql/api.py", line 993, in validate_object
    raise self.model.DoesNotExist(
Internal Server Error: /api/discussion/v1/threads/137/

Cause: _get_thread_and_context in lms/djangoapps/discussion/rest_api/api.py turns a missing thread into ThreadNotFoundError (404) by catching CommentClientRequestError, the error the old HTTP comments-service client raised. The comment client now calls forum.api.get_thread directly (comment_client/thread.py, Thread._retrieve), which raises forum.utils.ForumV2RequestError instead. Nothing maps it, so it escapes as a 500. Any endpoint that goes through _get_thread_and_context should behave the same way (GET/PATCH/DELETE of a thread, and a thread's comment list). The same except CommentClientRequestError pattern is used elsewhere in the module, e.g. _get_comment_and_context.

Impact: a client cannot tell "already deleted" from a server fault. An idempotent cleanup, such as a retry or a teardown after the UI deleted the post, fails with a 500 and an error in the logs.

Expected: 404, as before. Either the comment client translates ForumV2RequestError into CommentClientRequestError, or these except clauses also catch it.

Environment: Tutor main with tutor-forum, openedx-forum 0.4.7 (MySQL backend), 2026-09-23. Code unchanged on master as of 2026-10-13. Found by the Open edX end-to-end test suite.

Ngôn ngữ chính
Python
Star
8.2k
Fork
4.4k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
40

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openedx/openedx-platform

Tất cả issue của openedx/openedx-platform

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.