Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.6 - upgrade error with Shared Question Banks #226

Open
aspark21 opened this issue Dec 3, 2024 · 3 comments
Open

4.6 - upgrade error with Shared Question Banks #226

aspark21 opened this issue Dec 3, 2024 · 3 comments

Comments

@aspark21
Copy link

aspark21 commented Dec 3, 2024

Testing Moodle 4.6 for https://tracker.moodle.org/browse/MDLQA-19535

The following failures occur with this plugin that do not occur with 4.5

-->qtype_coderunner
Default exception handler: error/Invalid contextlevel for target category, must be CONTEXT_MODULE Debug: 
Error code: Invalid contextlevel for target category, must be CONTEXT_MODULE
$a contents: 
* line 146 of /question/format.php: core\exception\moodle_exception thrown
* line 182 of /question/type/coderunner/db/upgradelib.php: call to qformat_default->setCategory()
* line 166 of /question/type/coderunner/db/upgradelib.php: call to load_questions()
* line 50 of /question/type/coderunner/db/upgradelib.php: call to load_new_prototypes()
* line 437 of /question/type/coderunner/db/upgrade.php: call to update_question_types()
* line 7[57](https://github.com/ucl-isd/moodle-mysql-restore/actions/runs/12131616522/job/33824116798#step:8:58) of /lib/upgradelib.php: call to xmldb_qtype_coderunner_upgrade()
* line 1936 of /lib/upgradelib.php: call to upgrade_plugins()
* line 274 of /admin/cli/upgrade.php: call to upgrade_noncore()

!!! error/Invalid contextlevel for target category, must be CONTEXT_MODULE !!!
!! 
Error code: Invalid contextlevel for target category, must be CONTEXT_MODULE
$a contents:  !!
!! Stack trace: * line 146 of /question/format.php: core\exception\moodle_exception thrown
* line 182 of /question/type/coderunner/db/upgradelib.php: call to qformat_default->setCategory()
* line 166 of /question/type/coderunner/db/upgradelib.php: call to load_questions()
* line 50 of /question/type/coderunner/db/upgradelib.php: call to load_new_prototypes()
* line 437 of /question/type/coderunner/db/upgrade.php: call to update_question_types()
* line 757 of /lib/upgradelib.php: call to xmldb_qtype_coderunner_upgrade()
* line 1936 of /lib/upgradelib.php: call to upgrade_plugins()
* line 274 of /admin/cli/upgrade.php: call to upgrade_noncore()
@timhunt
Copy link
Collaborator

timhunt commented Dec 3, 2024

Yes. Moodle 5.0 / 4.6 will change how the question bank works, which means that the age-old hack (is that fair?) in CodeRunner that prototypes are stored in the system question bank will not work any more. There is no longer a system question bank.

So, this model needs a re-think. I have some thoughts about how best to deal with that, if you want to discuss it @trampgeek.

@timhunt
Copy link
Collaborator

timhunt commented Dec 3, 2024

No need for me to be mysterious. My outline solution is:

  1. There should be a specific Question bank (mod_qbank instance) in the front-page course, with a name like 'CodeRunner prototypes. Therefore, CodeRunner, install/upgrade should look for that, and auto-create if it does not already exist. (I would identify it using a suitable course_modules.idnumber, like qtype_coderunner-system-prototypes. (Here is the code to create a mod_qbank)
  2. To link questions to their prototype, we should stop using name-matching, and searching through contexts. Instead, we should make the link explicit, using the question_references DB table.
    • component would be 'qtype_coderunner'.
    • area could be 'prototype'.
    • usingcontextid is the context where the question using the prototype is - will need a question_moved event handler to keep this up to date). itemid is the question id of the question using the prototype.
    • questionbankentryid identifies which prototype this question uses.
    • version - I expect people will mostly set this to 'Always latest' (null), but acutally, there might be uses for being able to specify a fixed version of the prototype.
  3. Then, when editing a CodeRunner question, to select the prototype, there should be a UI like when you pick a question to add to a quiz, to pick a prototype question.

An advantage of using question_references is that then, for example, the question bank will prevent people from deleting prototyes that are in use.

@trampgeek
Copy link
Owner

Ouch. This is very worrying. We're only just recovering from the introduction of question versioning :-)

We're worried about the idea of linking questions to their prototypes using the question references DB table. Some of the concerns have already been outlined on a CodeRunner forum posting: https://coderunner.org.nz/mod/forum/discuss.php?d=570 There, we talk about the problems with exporting a quiz but similar and possibly even more serious concerns arise when backing up and restoring courses.

For example, suppose we have a question bank of prototypes that we share between two courses. We now backup both courses at the end of the academic year, ready for setting up our new year's server. How do we manage the question links in this case. Do both course backups include the shared question bank? Or is that backed up separately? In both cases, there seems to be a problem in re-establishing the question references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants