Skip to content

Assessment overwrites question feedback flags omitted from article config #232

Description

@swashbuck

TL;DR: Article-level assessment config overwrites question components' _canShowFeedback / _canShowMarking / _canShowModelAnswer even when those properties are omitted.

Summary

Issue #65 was closed as fixed in v2.0.5 (2015). The fix added a hasOwnProperty guard in the override path so that when an author omitted _canShowFeedback / _canShowModelAnswer from the article's _assessment._questions block, the question component's own value was preserved.

The same bug has since returned via two changes that together defeat the original fix:

  1. The introduction of assessmentConfigDefaults._questions (with all three properties defaulting to false) at the top of adapt-assessmentArticleModel.js. getConfig() deep-merges these defaults with the article config, so "omitted" properties get filled in as false before any downstream code runs.
  2. PR assessment: _canShowMarking & _canShowModelAnswer settings not applied on restore #2693 #130 (April 2021, fixing framework issue #2693) added a new method setupCurrentQuestionComponents() that blunt-sets _canShowFeedback, _canShowMarking, and _canShowModelAnswer on every question component during init() and after assessment reset, with no hasOwnProperty check.

The combined effect: the original v2.0.5 fix in _overrideQuestionComponentSettings() (which still uses hasOwnProperty) is bypassed because setupCurrentQuestionComponents() runs first and overwrites component values from the merged-with-defaults config.

Reproduction

  1. Place a question component (e.g. an mcq) with "_attempts": 1 inside an assessment article.
  2. In the component's components.json entry, set "_canShowModelAnswer": true.
  3. In the article's _assessment._questions block, either:
    • Omit _canShowModelAnswer entirely, or
    • Set "_canShowModelAnswer": false.
  4. Run the course. Submit an incorrect answer to exhaust the attempt.

Expected (per #65): When the property is omitted from the article, the question's own _canShowModelAnswer: true is respected and the Show Correct Answer button appears.

Actual: The button never appears. The article-level (or defaulted) false overrides the component value regardless of whether the author specified it.

Root cause - code references

js/adapt-assessmentArticleModel.js (v5.4.1):

Regression timeline

Suggested fix

Two changes needed; both are required because they reinforce each other:

  1. In setupCurrentQuestionComponents(), add hasOwnProperty guards mirroring _getMarkingSettings():

    setupCurrentQuestionComponents() {
      const assessmentQuestionsConfig = this.getConfig()._questions;
      const newSettings = {};
      ['_canShowFeedback', '_canShowMarking', '_canShowModelAnswer'].forEach(key => {
        if (Object.prototype.hasOwnProperty.call(assessmentQuestionsConfig, key)) {
          newSettings[key] = assessmentQuestionsConfig[key];
        }
      });
      if (Object.keys(newSettings).length === 0) return;
      this._getAllQuestionComponents().forEach(component => component.set(newSettings));
    },
  2. Remove _canShowFeedback, _canShowMarking, _canShowModelAnswer from assessmentConfigDefaults._questions so that omission in articles.json produces genuinely undefined values rather than defaulted false. The QuestionModel already defaults these to true at the component level, which is the appropriate fallback.

‼️ Backward compatibility risk

Existing courses that author _canShowMarking: false etc. at the article level are unaffected - the property is still defined, hasOwnProperty returns true, behavior is unchanged.

Existing courses that omitted the property and were relying on the implicit false default would see a behavior change: questions would start showing model answers / marking. This is technically a behavior change but matches both the documented behavior (#65) and the QuestionModel defaults. May warrant a minor version bump and release-note callout, or an opt-in property (e.g. _respectComponentOverrides) for safety.

Use case

In the project that surfaced this, one question in an assessment article needs to expose the Show Correct Answer button while the others do not. Currently impossible without a custom extension or fork.


Posted via collaboration with Claude Code.

Metadata

Metadata

Assignees

Labels

Type

Projects

Status
Needs Reviewing

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions