v3 notification preferences: PUT with email_cadence but no notification_channel raises KeyError (500)

Đang mở Phù hợp với người mới
#39,221 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

Chưa có ai nhận issue này.

  • #39241 của @mvanhorn — đã đóng, không merge
  • #39278 của @florianaltendorfer — đã đóng, không merge

Đá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
66/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với PUT tới /api/notifications/v3/configurations/ bằng payload trong issue, payload này sẽ tái hiện KeyError trong _prepare_update_data. So sánh phương thức này và _log_preference_update_event với _prepare_response_data, phương thức đã suy ra email_cadence làm kênh, rồi kiểm tra UserNotificationPreferenceUpdateAllSerializer.validate(). Hoàn thành khi yêu cầu thành công với kênh được suy ra, hoặc trả về 400 nêu tên trường. Maintainer cần chọn hành vi mong muốn trước khi thực hiện thay đổi.

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

Mô tả

bug

PUT /api/notifications/v3/configurations/ with an e-mail cadence and no notification_channel:

{"notification_app": "discussion", "notification_type": "grouped_notification",
 "email_cadence": "Weekly"}

passes validation, then fails in the view:

KeyError: 'notification_channel'
  in _prepare_update_data
Internal Server Error: /api/notifications/v3/configurations/

With "notification_channel": "email_cadence" added, the same update succeeds (200). The account MFE always sends the channel, so this is only reachable through the API.

Cause: UserNotificationPreferenceUpdateAllSerializer.validate() deliberately lets email_cadence stand in for the channel (it only requires notification_channel when there is no email_cadence), and NotificationPreferencesViewV3._prepare_response_data infers channel = 'email_cadence' in that case. But _prepare_update_data and _log_preference_update_event both read validated_data['notification_channel'] directly, so the request 500s before the update is applied.

Expected: infer email_cadence as the channel in _prepare_update_data and _log_preference_update_event, as _prepare_response_data already does (or, if the channel is meant to be mandatory, require it in the serializer so the client gets a 400 naming the field).

Environment: Tutor main, image of 2026-09-18; 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.