{"record":{"id":"2f89d7cbf4b85100","repo":"moodle/moodle","slug":"activity-cannot-be-used-as-the-default-idnumber-the-idnumber","errorCode":null,"errorMessage":"Activity '' cannot be used as the default idnumber. The idnumber has a max length of 100 chars. Please manually specify an idnumber.","messagePattern":"Activity '' cannot be used as the default idnumber\\. The idnumber has a max length of 100 chars\\. Please manually specify an idnumber\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"public/lib/behat/classes/behat_core_generator.php","lineNumber":461,"sourceCode":"\n        // The the_following_exists() method checks that the field exists.\n        $activityname = $data['activity'];\n        unset($data['activity']);\n\n        // Convert scale name into scale id (negative number indicates using scale).\n        if (isset($data['grade']) && strlen($data['grade']) && !is_number($data['grade'])) {\n            $data['grade'] = - $this->get_scale_id($data['grade']);\n            require_once(\"$CFG->libdir/grade/constants.php\");\n\n            if (!isset($data['gradetype'])) {\n                $data['gradetype'] = GRADE_TYPE_SCALE;\n            }\n        }\n\n        if (!array_key_exists('idnumber', $data)) {\n            $data['idnumber'] = $data['name'];\n            if (strlen($data['name']) > 100) {\n                throw new Exception(\n                    \"Activity '{$activityname}' cannot be used as the default idnumber. \" .\n                    \"The idnumber has a max length of 100 chars. \" .\n                    \"Please manually specify an idnumber.\"\n                );\n            }\n        }\n\n        // We split $data in the activity $record and the course module $options.\n        $cmoptions = array();\n        $cmcolumns = $DB->get_columns('course_modules');\n        foreach ($cmcolumns as $key => $value) {\n            if (isset($data[$key])) {\n                $cmoptions[$key] = $data[$key];\n            }\n        }\n\n        $this->datagenerator->create_module($activityname, $data, $cmoptions);\n    }","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/behat/classes/behat_core_generator.php#L443-L479","documentation":"behat_core_generator::process_activity() defaults an activity's idnumber to its name. Because idnumbers are limited to 100 characters, when the activity name exceeds that length and no explicit idnumber was given, it throws this Exception telling the author to specify an idnumber manually.","triggerScenarios":"Using an activity creation Behat step with a very long activity name and no idnumber column/value in the data.","commonSituations":"Verbose descriptive activity names in feature files; copied step data with long titles; localised names plus suffixes pushing past 100 chars.","solutions":["Add an idnumber (≤100 chars) to the activity data in the Behat step","Shorten the activity name to ≤100 characters","If the test doesn't rely on idnumber, use a concise name and reference it elsewhere by name","Centralise long names in a constants/fixtures file with a short idnumber mapping"],"exampleFix":"// before\n| activity | name | course |\n| forum    | A very long forum name exceeding one hundred characters ... | C1 |\n// after\n| activity | name | idnumber | course |\n| forum    | A very long forum name exceeding one hundred characters ... | forum1 | C1 |","handlingStrategy":"validation","validationCode":"if (array_key_exists('idnumber', $data) && strlen($data['idnumber']) > 100) {\n  throw new \\InvalidArgumentException('idnumber exceeds 100 chars');\n}\nif (!array_key_exists('idnumber', $data) && strlen($data['name']) > 100) {\n  throw new \\InvalidArgumentException('name too long for default idnumber; specify idnumber');\n}","typeGuard":"is_string($data['name'] ?? null) && (isset($data['idnumber']) ? strlen($data['idnumber']) <= 100 : strlen($data['name']) <= 100)","tryCatchPattern":"try { $this->create_activity($data); }\ncatch (\\Exception $e) {\n  if (str_contains($e->getMessage(), 'default idnumber')) { /* add explicit idnumber */ }\n  throw $e;\n}","preventionTips":["Always provide a short explicit idnumber when activity names are long","Keep test activity names concise (<100 chars)","Adopt a naming convention pairing long display names with short idnumbers","Validate table data lengths in CI before running Behat"],"tags":["behat","moodle","activities","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}