Serializers accept values the database or later code rejects

Aperta
#6,394 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Stack tecnologico
django, python

Direzione di ricerca

Start with the four serializers linked in the issue: the admin user, community library submission, and channel serializers, then read the validation strategy in #6387. Add regression tests for each listed input and check that invalid requests return 400 without saving; verify that null resolution_reason behaves like an omitted field and that approving object-shaped categories exports the channel and marks the submission live.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

DEV: backend

Overview

Some serializers accept values that the database, or the code that runs after validation, then rejects. The request passes validation and fails on save, returning 500, or saves data that breaks later.

Complexity: Medium
Target branch: hotfixes

Context

All inputs below were reproduced:

  • The admin user serializer's disk_space is a DRF FloatField, which accepts infinity. PATCH /api/admin-users/<id> with {"disk_space": "1e400"} raises ValueError: Out of range float values are not JSON compliant.
  • The community library resolve serializer calls .strip() on resolution_reason and feedback_notes, which accept null. Rejecting with either set to null raises AttributeError.
  • ChannelSerializer takes id from the model's 32-character CharField. POST /api/channel with {"id": "abc", "name": "x"} returns 201 and creates a channel that the channels/<32 characters>/ routes can't open. Related: #5783.
  • Community library submission categories accepts any JSON. A list passes validation, and approving the submission then raises AttributeError on categories.items(). resolve returns 200 with status APPROVED, but the channel never goes live.
The Change
  • Each serializer in Context should enforce the database's limits and the types the code after it expects, following the strategy in #6387.
  • A channel id should be a 32-character hex UUID.
  • categories should be an object mapping category ids to booleans, as the frontend sends it. The test fixtures that use a list should change to match.
Acceptance Criteria
General
  • Every input in Context returns 400 and saves nothing.
  • Rejecting a submission with resolution_reason: null gets the same response as omitting resolution_reason.
  • Approving a submission whose categories is an object exports the channel and marks the submission live.
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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di learningequality/studio

Tutte le issue di learningequality/studio

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.