Public v2 endpoints answer 304 before the view runs and cache error responses

Aperta
#6,408 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à
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
django, python
Ambito
api, backend, testing

Direzione di ricerca

Read contentcuration/kolibri_public/views.py around metadata_cache and get_last_modified, then inspect the tests for the contentnode and contentnode_tree endpoints. Add coverage for conditional requests, error response cache headers, and unchanged caching on successful responses; done means all listed acceptance criteria pass.

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

Descrizione

DEV: backend

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

metadata_cache wraps every public v2 endpoint in Django's last_modified, keyed on the newest ChannelMetadata.last_updated across all channels. Django answers a request whose If-Modified-Since is later than that with 304 before the view runs, so a request for a missing node, or with invalid parameters, gets 304 instead of 404 or 400. The decorator also marks error responses public and cacheable for 5 minutes, so a CDN serves them to everyone.

Complexity: Low
Target branch: hotfixes

Context
  • metadata_cache and get_last_modified apply last_modified, patch_response_headers and patch_cache_control(public=True) to every response.
  • Reproduced: GET /api/public/v2/contentnode/<nonexistent id>/ with an If-Modified-Since later than the newest channel update returns 304. A 404 or 400 response carries Cache-Control: max-age=300, public, stale-while-revalidate=100.
The Change
  • A conditional request should get 304 only when the view would otherwise return 200.
  • Error responses should not be marked public or cacheable.
Acceptance Criteria
General
  • A request for a missing node or with invalid parameters returns its 404 or 400 whatever its If-Modified-Since.
  • 4xx and 5xx responses from public v2 endpoints carry no public Cache-Control or max-age.
  • 200 responses keep their current caching headers, and conditional requests for them still get 304.
Testing
  • Tests cover each criterion on the contentnode and contentnode_tree endpoints.

AI usage

I scoped the audit. 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.