Django exceptions reach DRF as 500
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- django, python
- Domain
- backend-api-design
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- JavaScript
- Stars
- 214
- Forks
- 327
- Avg merge
- 17h 5m
- Merged PRs (30d)
- 25
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from learningequality/studio
-
Community library status changes don't update `date_updated`Possibly taken @ArpitaSamanta10 claimed this 14 days ago. Opencommunity-contribution-in-progress DEV: backend good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
learningequality/studio#6414 · 8 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Activation key can activate a different account whose email differs only in casePossibly taken @Madhu-priya123 claimed this 5 days ago. OpenDEV: backend
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
learningequality/studio#6410 · 2 comments ·
Maintainers usually reply within 1 day
-
DEV: backend
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
learningequality/studio#6409 ·
Maintainers usually reply within 1 day
-
DEV: backend
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
learningequality/studio#6407 ·
Maintainers usually reply within 1 day
-
Stripe webhook accepts events when no webhook secret is configuredPossibly taken @adibmbrk claimed this 14 days ago. Opencommunity-contribution-in-progress DEV: backend good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
learningequality/studio#6404 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in learningequality/studio
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
babalae/bettergi-scripts-list#3905 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] "Configure Colota" opens Colota with "Invalid configuration: No configuration data in URL"Open
Difficulty 1/5 1-3 hours Newbie friendliness 87/100
dedicatedcode/reitti#1445 ·
Maintainers usually reply within 1 day
-
New tool: Uncle DeskPossibly taken @github-actions claimed this today. Opensubmission triage
Difficulty 1/5 Under an hour Newbie friendliness 85/100
kausalflow/tools#384 · 1 comment ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
area: css
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day