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

未关闭 适合新手
#39,221 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #39241 来自 @mvanhorn —— 已关闭,未合并
  • #39278 来自 @florianaltendorfer —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从使用 issue 中的 payload 对 /api/notifications/v3/configurations/ 发起 PUT 请求开始,这应该能复现 _prepare_update_data 中的 KeyError。将该方法和 _log_preference_update_event 与 _prepare_response_data 进行比较,后者已经将 email_cadence 推断为渠道,并检查 UserNotificationPreferenceUpdateAllSerializer.validate()。完成的标准是:请求推断出渠道并成功,或返回指明字段的 400。维护者必须在修改前选定所需的行为。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
8.2k
派生
4.4k
平均合并
2 天 10 小时
30 天内合并 PR
40

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openedx/openedx-platform 的其他 Issue

查看 openedx/openedx-platform 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。