Skip to content

[QTI] Cannot publish QTI packages with formulas in answer choices #5958

@AlexVelezLl

Description

@AlexVelezLl

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

Observed behavior

Formulas can be added to the question prompt in a QTI assessment without issue, but adding a formula to an answer choice (simple choice / choiceInteraction) causes the backend to fail at publish time with a pydantic validation error.

The error indicates that Math elements are not recognized as valid children of SimpleChoice — only FlowContentElement or TextNode are accepted — so any answer choice containing a formula cannot be exported to a QTI package.

Errors and logs

2 validation errors for SimpleChoice
children.0.FlowContentElement
  Input should be a valid dictionary or instance of FlowContentElement [type=model_type, input_value=Math(id_=None, class_=Non...Node(text='a^{b}')])])]), input_type=Math]
    For further information visit https://errors.pydantic.dev/2.12/v/model_type
children.0.`function-before[functools.partial(<function coerce_str_to_model at 0x11740beb0>, <class 'contentcuration.utils.assessment.qti.base.TextNode'>)(), TextNode]`
  Input should be a valid dictionary or instance of TextNode [type=model_type, input_value=Math(id_=None, class_=Non...Node(text='a^{b}')])])]), input_type=Math]
    For further information visit https://errors.pydantic.dev/2.12/v/model_type

Expected behavior

Formulas should be supported in answer choices (simple choices) as well as in question prompts. A QTI package containing formulas in any field should publish successfully.

User-facing consequences

  • Users cannot publish QTI packages if any answer choice contains a formula, blocking the export workflow entirely.
  • Formulas work in question prompts but not in answer choices, creating an inconsistent and confusing authoring experience.

Steps to reproduce

  1. Create an exercise in Studio. Set completion to Survey and add a free response question.
  2. Add a single-choice question and insert a formula into one of its answer choices using the formula editor in the RTE.
  3. Attempt to publish the exercise as a QTI package.
  4. Observe that the publish fails with a pydantic validation error on SimpleChoice.

Context

  • The failure occurs in the QTI export backend, in the pydantic model for SimpleChoice.
  • The Math element type is not included as a valid child type of SimpleChoice, unlike the question prompt which correctly supports it.
  • Relevant code: contentcuration/utils/assessment/qti/ and contentcuration/utils/publish.py.

Acceptance Criteria

  • Formulas can be added to answer choices (simple choices) in a QTI assessment without causing a publish error.
  • A QTI package containing formulas in both question prompts and answer choices publishes successfully.
  • The Math element is recognized as a valid child of SimpleChoice in the QTI pydantic model.

AI usage

Drafted with Claude Code. Reproduction steps and acceptance criteria were reviewed and confirmed manually.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions