Serializers accept values the database or later code rejects

Offen
#6,394 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
django, python

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
212
Forks
321
Ø Merge
1 T. 7 Std.
Gemergte PRs (30 T.)
14

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus learningequality/studio

Alle Issues in learningequality/studio

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.