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

未关闭
#6,408 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
django, python
领域
api, backend, testing

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
212
派生
321
平均合并
1 天 7 小时
30 天内合并 PR
14

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

learningequality/studio 的其他 Issue

查看 learningequality/studio 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。