Quizzes with QTI questions can't be saved: `question_id` must be a hex UUID
🙂 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
Observed behavior
A coach adds questions from a QTI exercise to a quiz and clicks Save. The quiz isn't saved, and the editor shows "There was a problem saving this quiz".
POST /api/exams/exam/ returns 400, one error per question:
[{"id": "INVALID", "metadata": {"field": "question_sources.questions.question_id", "message": "Must be a valid UUID."}}, ...]
The questions it sent:
{"exercise_id": "4975a79cf4584bcab01c38493fcd9794", "question_id": "Kiqr_v4mwSSKrndkc0pgXpw", "counter_in_exercise": 5, "title": ""}
Cause
QuestionSourceSerializer.question_id is a HexUUIDField(format="hex") (kolibri/core/exams/viewsets/exam.py L55). It was added in #7866 to match exercise_id.
A QTI exercise's assessment_item_ids are the item identifiers from its QTI manifest. Studio writes them as K + 22 base64url characters (hex_to_qti_id in contentcuration/utils/assessment/qti/convert.py, and create_kolibri_assessment_metadata in publish.py). They aren't hex, so every QTI question fails validation.
The quiz editor's question selection uses assessment_item_ids as question_id. Nothing else in the backend parses question_id: the attempt log's item is <exercise_id>:<question_id>, a plain string.
Expected behavior
A coach can save a quiz with questions from QTI exercises, the same as Perseus exercises.
User-facing consequences
Coaches can't use QTI exercises in quizzes. This affects more exercises once Studio's unstable publishing reaches production. Since learningequality/studio@26b4b4a3a ("route nodes without perseus_question items to QTI packaging"), an exercise with no perseus_question items is published as a QTI package, and its assessment_item_ids come from the QTI manifest. That includes exercises made with Studio's own question editor. After that ships, newly published exercises like these can't be added to a Kolibri quiz.
Steps to reproduce
Through the API:
response = client.post(reverse("kolibri:core:exam-list"), {
..., # title, collection, assignments, etc.
"question_sources": [{"section_title": "", "learners_see_fixed_order": True, "questions": [
{"exercise_id": uuid4().hex, "question_id": "KQabcyK22Tx-8YmTmTKtGAA", "title": "", "counter_in_exercise": 1},
]}],
}, format="json")
response.status_code # 400, question_id "Must be a valid UUID."
In the UI:
- Import a channel with a non-survey QTI exercise. The Kolibri QA Channel's "Experiments > QTI > Hopefully QTI" is a survey and is hidden from quiz selection, so to try it locally I removed its
SURVEYmodality on my dev database. - As a coach, go to Quizzes → New quiz → Add questions, and select the QTI exercise.
- Click Save. "There was a problem saving this quiz" appears, and the request returns the 400 above.
Related
- #15375: answers to QTI questions are rejected because the QTI viewer's
checkAnswer()returnsoutcomes.SCOREand nocorrect. Its diagnosis notes that the quiz renderers hit the same thing. I confirmed this on a QTI quiz I created directly in the database to get past the save error. InExamPage, the rejectedPUT /api/logger/trackprogress/(interactions.correct: This field is required.) also sends the learner back to the class page. So QTI in quizzes needs both fixes. - #11428 (QTI rendering)
Context
- Kolibri
developat 5b5c7dc4d7 (dev server) - macOS 26.6.2, Chromium
Possible fixes, which I'd be glad to work on once the approach is agreed:
- Make
question_idaCharField. Simplest, and accepts any QTI item identifier, including ones from content not made in Studio. It drops the format check from #7866. - Keep a format check that accepts either a hex UUID or Studio's QTI identifier (
K+ 22 base64url characters, fromhex_to_qti_id). Stays strict, but any other QTI identifier format would still fail. - Validate that each
question_idis in its exercise'sassessmentmetadata.assessment_item_ids. The strongest check and independent of the format, but it adds a content query on every quiz save.
A test that saves a quiz with a QTI-style question_id through exam-list (and exam-detail for updates) would cover it.
AI usage
I used Claude Code to test QTI content in coach quizzes on my local Kolibri. It found the save error, traced it to the question_id validator and to how Studio publishes QTI item identifiers, checked #15375 and related issues, and drafted this issue. I checked the code references and reproduced the error in the UI and through the API.
Hi @rtibbles, I re-checked this on the latest develop (b67121093b): QuestionSourceSerializer still rejects Studio's QTI item ids (K + 22 base64url characters) with "Must be a valid UUID", so coaches still can't save quizzes with QTI questions. #15571 fixes the answer side (#15375), but not this validator, so QTI in quizzes needs both.
I'd be glad to fix it. My suggestion is option 1 (make question_id a CharField), since nothing in the backend parses it and the attempt log already stores it as a plain string. I'm happy to go with option 2 or 3 if you'd prefer a stricter check. Could you assign it to me if that works?
@rtibblesbot please validate this issue.
Verdict: claim holds
Evidence: kolibri/core/exams/viewsets/exam.py:55 on develop at f72936bd41: question_id = HexUUIDField(format="hex")
HexUUIDField(kolibri/core/api.py:446) is DRF'sUUIDFieldwithformat="hex", so a non-hex id likeKiqr_v4mwSSKrndkc0pgXpwfails with "Must be a valid UUID."- The validator came from #7866 (05bf32ad99), which validated
question_idthe same way asexercise_id. - The coach quiz editor sets
question_idfromassessmentmetadata.assessment_item_ids(kolibri/plugins/coach/frontend/utils/selectQuestions.js:12,useQuizCreation.js:477), so a QTI exercise's item ids reach this validator unchanged. AttemptLog.itemis a plainCharField(max_length=200)(kolibri/core/logger/models.py:282), as the issue says.- No open or recently closed issue reports this. #15375 (closed) covers the QTI answer side, not saving the quiz.
- Not checked here: the Studio QTI id format (
K+ 22 base64url characters).
Written by rtibblesbot, an LLM-based coding agent.
Approach: make question_id a CharField(max_length=200) (matching AttemptLog.item) with a regex, not a check for K + 22 characters only.
Studio publishes a QTI exercise's assessment_item_ids from the resource identifiers in its imsmanifest.xml (get_assessment_ids_from_manifest), and those come in more than one shape:
- Converted legacy/Perseus items:
hex_to_qti_id(assessment_id)→K+ 22 base64url characters (utils/assessment/qti/convert.py). - Items authored in the QTI editor: the item XML's own
identifier, created bygenerateRandomSlug('item')→ e.g.item_k3j9x0ab(QTIEditor/serialization/createBlankItem.js). - Non-QTI exercises: 32-character hex UUIDs, which can start with a digit.
Suggested pattern: ^(?:[0-9a-f]{32}|[A-Za-z_][A-Za-z0-9_.-]*)$
Thanks for assigning this. The fix, using the pattern you suggested, is up in https://github.com/learningequality/kolibri/pull/15698.