Skip to content

Fix mcq v4.2.0 migration throws on components without _items #263

Description

@swashbuck

Subject of the issue

The v4.1.0 > v4.2.0 migration throws a TypeError when a course contains an mcq component without an _items array. The mutate steps access MCQ._items.forEach(...) directly with no guard, so an itemless mcq crashes the whole migration (and any authoring-tool import that runs it). The bug is present on master (7.7.2).

Your environment

  • Framework 5.56.2, adapt-contrib-mcq 7.7.2 (also present on master)
  • N/A (build-time migration, not browser)

Steps to reproduce

  1. Take a course with an mcq component that has no _items property.
  2. Run the mcq migrations against it, e.g. grunt migration:test --file=adapt-contrib-mcq, or import the course into the authoring tool. (The migration's own testSuccessWhere already includes an itemless mcq: { _id: 'c-100', _component: 'mcq' }.)

Expected behaviour

An mcq with no _items should be handled gracefully (nothing to update) and the migration should pass.

Actual behaviour

The migration throws:

mutateContent -- MCQ - add item _isPartlyCorrect attribute TypeError: Cannot read properties of undefined (reading 'forEach')

In migrations/v4.js, the v4.1.0 > v4.2.0 block does MCQ._items.forEach(...) in the "add item _isPartlyCorrect" and "add item _score" mutates, and MCQ._items.every(...) in the matching checks, with no protection for a missing _items. (Other components such as accordion/hotgraphic use _items?.forEach(...).)

Suggested Fix (if known)

Guard _items in that block, e.g. MCQ._items?.forEach(...) in the mutates and (MCQ._items ?? []).every(...) in the checks.


Posted via collaboration with Claude Code

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions