Django exceptions reach DRF as 500
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
Start with contentcuration/contentcuration/viewsets/base.py and the serialize_object behavior linked in the issue, then read the related DRF views and the exception handler strategy in #6387. Add regression tests for each input listed in Context and verify malformed detail-route pks return 404, invalid parameters and submission states return 400, and Django ObjectDoesNotExist returns 404.
由索引模型根据 Issue 内容生成。
描述
Overview
Some code raises Django's ValidationError, ObjectDoesNotExist or FieldError inside DRF views. DRF converts only its own exceptions, Http404 and PermissionDenied, so these return 500. BaseValuesViewset.serialize_object also crashes on some malformed pks before it can return its 404.
Complexity: Medium
Target branch: hotfixes
Context
All inputs below were reproduced:
BaseValuesViewset.serialize_object:- On a model with an integer pk,
GET /api/assessmentitem/abcraisesUnboundLocalError, because.filter()fails beforequerysetis assigned. Kolibri fixed this in learningequality/kolibri@eeb4c8207e. - On
SavedSearch, whose pk is a DjangoUUIDField,GET /api/search/saved-search/abcraises DjangoValidationError, which isn't in the caught tuple. - Affected detail routes:
assessmentitem,user,admin-users,bookmark,channeluser,communitylibrary_submission,admin_communitylibrary_submission,saved-search.
- On a model with an integer pk,
ChannelUserViewSet:GET /api/channeluser/<id>without?channel=raisesFieldError: Cannot resolve keyword 'can_edit'.can_editandcan_viewexist only once the channel filter has annotated them.ContentNodeTreeViewset.validate_and_return_params:depth=3,depth=abc,next__gt=-1andnext__gt=abcraise DjangoValidationErroron the anonymous public tree endpoint. Kolibri has the same code (learningequality/kolibri#15835).resolvecallsCommunityLibrarySubmission.save, which raises DjangoValidationErrorwhen the author is no longer a channel editor or the channel has since become public.
The Change
serialize_objectshould follow Kolibri's fix and also treat DjangoValidationErroras not found.channeluserretrieve without?channel=should respond as the list route does. Each other site should return 400 instead of 500.- The custom
EXCEPTION_HANDLERfrom the strategy in #6387 lands in this issue.
Acceptance Criteria
General
- Each detail route listed in Context returns 404 for a malformed pk.
-
channeluserretrieve without?channel=gets the same response as the list route without?channel=. - Invalid
depthandnext__gtvalues return 400. -
resolvereturns 400 with the validation message for the two submission states in Context. - Django
ValidationErrorraised in any DRF view returns 400, andObjectDoesNotExistreturns 404.
Testing
- Each input in Context has a regression test.
AI usage
I scoped the audit and chose the validation strategy in #6387. Claude Code found and reproduced these failures and drafted this issue.
- 主要语言
- Python
- 星标
- 212
- 派生
- 321
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 14
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
learningequality/studio 的其他 Issue
-
Community library status changes don't update `date_updated`可能已有人在做 @ArpitaSamanta10 今天认领。 未关闭community-contribution-in-progress DEV: backend good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
learningequality/studio#6414 · 8 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
DEV: backend
难度 2/5 1-3 小时 新手友好度 82/100
learningequality/studio#6410 ·
维护者通常 1 天内回复
-
DEV: backend
难度 2/5 1-3 小时 新手友好度 76/100
learningequality/studio#6409 ·
维护者通常 1 天内回复
-
DEV: backend
难度 2/5 1-3 小时 新手友好度 78/100
learningequality/studio#6407 ·
维护者通常 1 天内回复
-
Stripe webhook accepts events when no webhook secret is configured可能已有人在做 @adibmbrk 今天认领。 未关闭community-contribution-in-progress DEV: backend good first issue help wanted
难度 2/5 1-3 小时 新手友好度 78/100
learningequality/studio#6404 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 learningequality/studio 的全部 Issue
相似的 Issue
-
area: ci bug good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
hffgzktbcc-blip/ounce-core#484 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
ranxianglei/billion-context#7063 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
-
needs-triage
难度 2/5 1-3 小时 新手友好度 84/100
MakazhanAlpamys/Soup#2971 ·
维护者通常 1 天内回复