kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

[QTI] Use File.included_presets for more comprehensive import renderability gating

Open rtibbles opened this issue 5 months ago • 7 comments

Overview

Evolve Kolibri's renderable filter to honor File.included_presets (learningequality/studio#6004), so a node imports only when some file's required presets are all locally renderable.

Complexity: Medium Target branch: develop

Context

  • renderable_contentnodes_q_filter (content_types_tools.py) is Q(kind=TOPIC) | OR(Q(files__preset=p) for p in installed renderers' presets) — a node is renderable if any file's own preset is renderable. It can't express a file that needs more than one renderer.
  • Studio publishes File.included_presets, a bitmask of every preset a file needs — its own (learningequality/studio#6004) plus embedded (the qti | exercise mixed-file rule, learningequality/studio#6006).
  • A mixed Perseus-in-QTI file needs both qti and exercise; the OR-of-own-preset filter would wrongly import it where only the QTI renderer is installed.

The Change

  • Bump le-utils to 0.2.18 (pyproject.toml, currently 0.2.17); it adds RENDERABLE_PRESETS_ORDER in le_utils/constants/format_presets.py.
  • Derive every preset bit from that list: bit = 2 ** RENDERABLE_PRESETS_ORDER.index(preset). It is append-only; Kolibri defines no ordering of its own.
  • Build the available-presets bitmask by ORing the bits of every preset across installed ContentRendererHook.presets.
  • Add included_presets to the content File model as a nullable integer bitmask with no default.
  • No default keeps the add-column migration metadata-only (a default rewrites the table on older Postgres).
  • Bump the content DB schema version (V5 → V6).
  • Replace the renderable filter: a node is renderable if kind=TOPIC, or any file has included_presets IS NOT NULL AND included_presets & ~available == 0. NULL reads as a subset of nothing and never qualifies.

Populating included_presets for pre-V6 data

included_presets is published only on V6 channel databases (learningequality/studio#6004). Backfill every File that predates it — imported from a ≤V5 channel DB, or already local before the column existed:

Set the bit for the file's own preset when preset in RENDERABLE_PRESETS_ORDER; leave NULL otherwise (supplementary files need no renderer).

This reproduces today's single-preset gating. No file is ever stored as 0 — renderable files set ≥1 bit, others stay NULL — so the filter's IS NOT NULL needs no zero-guard.

Older channel-DB imports (schema ≤ V5), in channel_import.py:

  • Register VERSION_6: ChannelImport (naive one-to-one).
  • A ≤V5 source lacks the column, so import leaves included_presets NULL.
  • Add NoIncludedPresetsChannelImport(ChannelImport) with a File post op set_included_presets_from_preset — shape of set_learning_activities_from_kind: per-preset UPDATE file SET included_presets=? WHERE preset=? AND channel_id=?.
  • Have NoLearningActivitiesChannelImport extend it, so V1–V5 and older inherit the backfill.
  • MIN_CONTENT_SCHEMA_VERSION stays V5.

Existing local DB:

  • Backfill via a Kolibri upgrade task in kolibri/core/content/upgrade.py — @version_upgrade(old_version="<0.20.0"), pattern of contentnode_modality_annotation_update.
  • Apply the same rule across the whole File table.
  • Use the upgrade task, not a data migration.

Acceptance Criteria

  • [ ] A mixed Perseus-in-QTI node imports only where both the qti and exercise renderers are installed
  • [ ] It is gated out where the exercise renderer is absent
  • [ ] A dual-published node (separate qti and perseus files) imports where either renderer is installed
  • [ ] Existing single-preset content gates exactly as today
  • [ ] Tests cover the mixed (all-of-a-file's-presets) and dual-publish (any-file) cases
  • [ ] le-utils bumped to 0.2.18; all bit math derives from RENDERABLE_PRESETS_ORDER
  • [ ] included_presets is nullable with no default; the add-column migration is metadata-only
  • [ ] A file with NULL included_presets (unbackfilled or supplementary) never makes its node renderable
  • [ ] Importing a schema-≤V5 channel backfills included_presets from each file's preset; gating unchanged from today
  • [ ] The upgrade task backfills included_presets for File rows imported before the column existed
  • [ ] Tests cover both backfill paths (channel import + upgrade task) and the NULL gating

References

  • kolibri#11428 — Allow Kolibri to render QTI assessments

AI usage

Architecture decided with the maintainer across an iterative session: blanket QTI type with the item XML in raw_data; XSD-authoritative validation across all sources; a legacy→QTI global migration with an API-layer dual-read; ricecooker upload delegating to the AssessmentItem serializer; and a Perseus custom-interaction contract confirmed against the QTI 3.0 specification. Claude mapped the existing publish/validation/ricecooker code, proposed the breakdown, and drafted each issue; the maintainer steered every decision and reviewed throughout.

rtibbles avatar Jun 28 '26 03:06 rtibbles

Hi @rtibbles , Can I work on this issues?

DevilsAutumn avatar Jul 04 '26 04:07 DevilsAutumn

Hi! 👋

Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.

We really appreciate your willingness to help. 😊

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Jul 04 '26 04:07 learning-equality-bot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 11 '26 06:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 11 '26 09:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 11 '26 21:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 13 '26 00:07 rtibblesbot

Fixed in #14994

rtibbles avatar Jul 16 '26 19:07 rtibbles