Quizzes created before 0.17 can't be taken or reviewed: exam API drops their questions
🙂 Looking for an issue? Welcome! This issue is open for contribution. If this is the first time you’re requesting an issue, please:
- Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that don’t follow the guidelines won’t be answered.
- Confirm that you’ve read the guidelines in your comment.
Target branch: develop (regression in 0.20.0 alphas, not in 0.19.5)
Observed behavior
For any quiz with data_model_version 0, 1 or 2 (every quiz created before V3 sections arrived in 0.17), GET /api/exams/exam/<id>/ replaces each entry of question_sources with {"learners_see_fixed_order": false}.
Stored question_sources (V1):
[{"exercise_id": "5127051047b14b1c84dc745ddbca0864", "question_id": "76ca1b8d724d5143948ebd379fbefc03", "title": "..."}, ...]
API response:
"data_model_version": 1,
"question_sources": [{"learners_see_fixed_order": false}, {"learners_see_fixed_order": false}, {"learners_see_fixed_order": false}]
The frontend's convertExamQuestionSources then upgrades these empty entries to V3. Every question ends up with exercise_id undefined, so the exercises are requested with GET /api/content/contentnode/?ids=&no_available_filtering=true. As a result:
| Who | Where | What they see |
|---|---|---|
| Learner | Taking the quiz | Every question shows "Resource not found on device". Submit is blocked: "Unable to submit quiz because some resources are missing or not supported" |
| Coach | Quiz preview | "Resource not found on device" |
| Coach | A learner's quiz report | Score is shown, but every answer shows "Resource not found on device" |
The exercises are on the device (available=True). Only the API response is wrong.
Learner taking a V1 quiz:
Errors and logs
[Vue warn]: Duplicate keys detected: 'answer-history-item-undefined:undefined'. This may cause an update error.
found in ---> <AnswerHistory> at kolibri/plugins/learn/frontend/views/ExamPage/AnswerHistory.vue
Cause
#14842 moved ExamViewset to the serializer-derived ValuesViewset pattern. ExamSerializer.question_sources is QuizSectionSerializer(many=True) (kolibri/core/exams/viewsets/exam.py L87). Because it's a declared field, derive_values_from_serializer maps the raw JSON through field.to_representation (kolibri/core/utils/values_viewset/introspect.py L471–474).
QuizSectionSerializer describes a V3 section. A V0–V2 entry is a question (or a V0 exercise source), so it has none of the section fields. section_title, description and questions are required=False and get skipped, and learners_see_fixed_order falls back to its default. Each question becomes {"learners_see_fixed_order": false}.
In 0.19.5, ExamViewset listed question_sources in its explicit values, so the stored JSON was returned unchanged. Nothing upgrades stored quizzes to V3: migration 0007_bump_data_model_version_to_3 only changes the default, and kolibri/core/exams/upgrade.py has no conversion. So these quizzes are still V0–V2 in existing databases, and the frontend is expected to convert them on read.
Expected behavior
The exam API returns question_sources exactly as stored for every data_model_version, so the frontend can convert older quizzes as before. Learners can take and submit them, and coaches can preview them and review learners' answers.
User-facing consequences
After upgrading to 0.20, any facility that has quizzes from 0.16 or earlier, or syncs with a device running one, loses access to them:
- Learners can't finish an active old quiz.
- Coaches can no longer review learners' answers on old quizzes, which is historical report data.
Steps to reproduce
Through the API test client (the quickest):
exam = Exam.objects.create(title="legacy", collection=classroom, creator=admin, active=True, question_count=1, question_sources=[])
Exam.objects.filter(pk=exam.id).update(
data_model_version=1,
question_sources=[{"exercise_id": uuid4().hex, "question_id": uuid4().hex, "title": "Ex"}],
)
response = client.get(reverse("kolibri:core:exam-detail", kwargs={"pk": exam.id}))
response.data["question_sources"] # [{"learners_see_fixed_order": False}]
The same test fails for V0 ({exercise_id, number_of_questions, title}) and V2 ({exercise_id, question_id, title, counter_in_exercise}).
In the UI:
- Generate dev data with
kolibri manage generateuserdata. Its quizzes are V1, with all 3 exercises available on the device. - Sign in as a learner in the class and open an assigned quiz. Every question shows "Resource not found on device" and Submit is blocked.
- Sign in as a coach and open Quizzes → the quiz → Preview, or a learner's row in the report. Same message.
Context
- Kolibri
developat 9cd759ba45 (dev server); also in v0.20.0-alpha0 and alpha1 - Not in v0.19.5
- macOS 26.6.2, Chromium
- Kolibri QA Channel imported from Studio
Possible fixes, which I'd be glad to work on once the approach is agreed:
- Serialize
question_sourcesas raw JSON on read, and keepQuizSectionSerializerfor validating writes only (writes are already V3-only). - Pick the representation by
data_model_version, so V3 goes throughQuizSectionSerializerand older versions pass through unchanged.
A regression test that round-trips V0, V1 and V2 question_sources through exam-detail would cover it. No current test reads a pre-V3 quiz back from the API.
AI usage
I used Claude Code to drive a browser through learner and coach quiz flows on my local Kolibri, where it found this. It traced the empty ids= request back to the API response and the serializer, and drafted this issue. I checked the code references against develop and v0.19.5, reproduced it in the UI as a learner and a coach, ran a test that round-trips V0/V1/V2 question_sources through the API (all three fail), and edited the text.
Confirmed. Let's go with option 1, implemented as a custom field:
- Subclass DRF's
JSONFieldand overrideto_internal_valueto validate withQuizSectionSerializer(many=True), returning itsvalidated_data. - Use it for
question_sourcesonExamSerializer, so stored JSON is passed through unchanged on read. - Add a test under
override_settings(DEBUG=True)that reads V0, V1 and V2question_sourcesback throughexam-detail.
Opened https://github.com/learningequality/kolibri/pull/15535 with the JSONField approach and V0/V1/V2 round-trip tests under DEBUG=True.