Django exceptions reach DRF as 500
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend-api-design
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 212
- Fork
- 321
- Merge medio
- 1g 7h
- PR unite (30g)
- 14
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di learningequality/studio
-
Community library status changes don't update `date_updated`Forse già presa @ArpitaSamanta10 l’ha presa oggi. Apertacommunity-contribution-in-progress DEV: backend good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
learningequality/studio#6414 · 8 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
DEV: backend
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
learningequality/studio#6410 ·
I maintainer di solito rispondono entro 1 giorno
-
DEV: backend
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
learningequality/studio#6409 ·
I maintainer di solito rispondono entro 1 giorno
-
DEV: backend
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
learningequality/studio#6407 ·
I maintainer di solito rispondono entro 1 giorno
-
Stripe webhook accepts events when no webhook secret is configuredForse già presa @adibmbrk l’ha presa oggi. Apertacommunity-contribution-in-progress DEV: backend good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
learningequality/studio#6404 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di learningequality/studio
Issue simili
-
area: ci bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
hffgzktbcc-blip/ounce-core#484 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
ranxianglei/billion-context#7063 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
MakazhanAlpamys/Soup#2971 ·
I maintainer di solito rispondono entro 1 giorno