moodle/moodle · error · coding_exception

The 'relateduserid' value must be set.

Error message

The 'relateduserid' value must be set.

What it means

Custom validation hook (validate_data) in this core_competency event. Before the event is triggered, Moodle calls validate_data, and this implementation requires relateduserid to be set: a review-stopped event must record which user's competency review was stopped. It fires when code triggers the event without passing relateduserid in the event data — a coding error, since the event is meaningless without the affected user. Fix by including ['relateduserid' => $userid] when creating/triggering the event.

Solutions

  1. Provide 'relateduserid' when constructing the event
  2. Rely on create_from_user_competency() to set it correctly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at public/lib/classes/event/competency_user_competency_review_stopped.php:117 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/230fea7fd06298eb. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/classes/event/competency_user_competency_review_stopped.php:117

    }

    /**
     * Get_objectid_mapping method.
     *
     * @return string the name of the restore mapping the objectid links to
     */
    public static function get_objectid_mapping() {
        return base::NOT_MAPPED;
    }

    /**
     * Custom validation.
     *
     * Throw \coding_exception notice in case of any problems.
     */
    protected function validate_data() {
        if (!$this->relateduserid) {
            throw new \coding_exception('The \'relateduserid\' value must be set.');
        }
    }

}

View on GitHub (pinned to 48ea8c3322)