Issue with CodeRunner Prototypes in Moodle 4.6/5.0

Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Nick Kunz -
Number of replies: 10

Hi everyone,

I am currently testing CodeRunner in Moodle 4.6/5.0 and encountered an issue with how prototypes are handled. CodeRunner relies on the prototypes that are stored as system-wide questions in older versions of Moodle, but with the new way Moodle 4.6/5.0 manages question storage, I cannot get this to work.

What do I have to do in order to use the prototypes in the new Moodle version?

Any help would be greatly appreciated!
Thanks in advance.

In reply to Nick Kunz

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Richard Lobb -
The development branch on GitHub contains an alpha-level version of a CodeRunner that has been updated to handle Moodle 5. It runs the test suite ok but has had only minimal testing with the new multiple question banks.

We would be grateful if you could help with testing this new version. Just pull from GitHub and checkout development. It should work with new installs or during  Moodle version upgrades, and should correctly import courses from prior Moodles. However, these things are difficult to test comprehensively, so please let us know how you get on.
In reply to Richard Lobb

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Luca Bösch -
I'sorry to say I see

-->qtype_coderunner
Setting up CodeRunner question prototypes...
CodeRunner prototypes set up using qbank
Exception while installing CodeRunner question prototypes: Coding error detected, it must be fixed by a programmer: Upgrade failed: error creating system question bank
Default exception handler: Coding error detected, it must be fixed by a programmer: Upgrade failed: error creating system question bank Debug:
Error code: codingerror
* line 199 of /question/type/coderunner/db/upgradelib.php: core\exception\coding_exception thrown
* line 116 of /question/type/coderunner/db/upgradelib.php: call to moodle5_top_category()
* line 90 of /question/type/coderunner/db/upgradelib.php: call to update_question_types_with_qbank()
* line 77 of /question/type/coderunner/db/upgradelib.php: call to update_question_types_internal()
* line 437 of /question/type/coderunner/db/upgrade.php: call to update_question_types()
* line 758 of /lib/upgradelib.php: call to xmldb_qtype_coderunner_upgrade()
* line 1937 of /lib/upgradelib.php: call to upgrade_plugins()
* line 274 of /admin/cli/upgrade.php: call to upgrade_noncore()

!!! Coding error detected, it must be fixed by a programmer: Upgrade failed: error creating system question bank !!!
!!
Error code: codingerror !!
!! Stack trace: * line 199 of /question/type/coderunner/db/upgradelib.php: core\exception\coding_exception thrown
* line 116 of /question/type/coderunner/db/upgradelib.php: call to moodle5_top_category()
* line 90 of /question/type/coderunner/db/upgradelib.php: call to update_question_types_with_qbank()
* line 77 of /question/type/coderunner/db/upgradelib.php: call to update_question_types_internal()
* line 437 of /question/type/coderunner/db/upgrade.php: call to update_question_types()
* line 758 of /lib/upgradelib.php: call to xmldb_qtype_coderunner_upgrade()
* line 1937 of /lib/upgradelib.php: call to upgrade_plugins()
* line 274 of /admin/cli/upgrade.php: call to upgrade_noncore()
!!

during the update.

Best wishes
Luca
In reply to Luca Bösch

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Richard Lobb -
Thanks for reporting. Can you tell me what the upgrade path was, please, i.e. what version of Moodle you were upgrading from and what version you were upgrading to. Also, would you be able change line 199 of coderunner/db/upgradelib.php to

throw new coding_exception("Upgrade failed: error creating system question bank ($e)");

so that it reports what exception occurred, please?
In reply to Richard Lobb

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Luca Bösch -
Yes, sure.
It happens on a not clean sheet install, i.e. there's question banks, courses, questions etcetera already.
Moodle 4.6, and Moodle 5.0. It happens e.g. if you updated to one of those versions having qtype_coderunner from master branch, then switch to branch development and then run an php/cli/upgrade.php (or via update in the admin user interface).

The error says

Default exception handler: Coding error detected, it must be fixed by a programmer: Upgrade failed: error creating system question bank (core\exception\moodle_exception: Cannot be executed during upgrade in [dirroot]/lib/setuplib.php:1245 .

Many thanks,
Luca
In reply to Luca Bösch

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Richard Lobb -
Many thanks for the extra test info, Luca. Very helpful.

I've pushed an update that I think should solve the problem. Because the moodle5 qbank module isn't available during installs, I was deferring question prototype updates when running Moodle 5.0 installs do a post-install task. It seems I have to do the same for Moodle 5.0 updates.

I have done pretty minimal testing (just run the version upgrade on Moodle 4.5 and Moodle 4.6) as (a) it's Sunday and (b) I'm teaching a course with over 1000 students at present, so software development time is minimal. But the changes are pretty simple so I don't think it's likely I've broken anything and I *should* have at least fixed the bug you're reporting. Please confirm.

Thanks again for the help with testing.
In reply to Richard Lobb

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Luca Bösch -
Thanks to you, Richard!

The update passed and I can see the PROTOTYPE questions in the right spot I think but two things tell me something is not yet as expected: the 'create question' dialogue finding no prototype and a "Broken question (missing or duplicate prototype 'java_method'). Cannot be run." notification.


In reply to Luca Bösch

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Richard Lobb -
Hi Luca

I've moved this discussion to the developers forum while we get things sorted out.

I don't know why it's not working for you. We've just run a test, upgrading a Moodle 4.5 server with serveral courses to Moodle 5.0 and the existing questions work fine. However, we did do the upgrade with the development branch of coderunner in place, which you didn't do, so that might be a factor. All the same, if the prototypes are present in the Front Page question bank, you shouldn't be seeing the errors you're seeing since the new version of the code includes that context in all searches for prototypes.

So, can you clarify what you mean when you say "I can see the PROTOTYPE questions in the right spot I think", please?

On my Moodle 5.0 system, if I click the Home link (taking me to the Front Page course), and then choose the Question banks link, I get told that the "Question banks in this course" are the System shared question bank (a link). When I click that link I see all the CodeRunner built-in prototypes.

Is that working for you?

Richard
In reply to Richard Lobb

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Luca Bösch -
Hi Richard.
Yes I can see this System shared question bank with the CodeRunner built-in prototypes.
However it seems to me that in a course, I can only create/run CodeRunner questions when a prototypes exists within that course. If there is no prototype in the course question bank neither the question runs properly nor the chooser for the type in a CodeRunner question shows any option.
The impression is that somehow the prototypes in that System shared question bank in the front page course can't be 'seen' from anywhere.
In reply to Luca Bösch

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Luca Bösch -
Dear Richard.

I have been able to track back my issues to https://tracker.moodle.org/browse/MDL-84695.

Best,
Luca
In reply to Luca Bösch

Re: Issue with CodeRunner Prototypes in Moodle 4.6/5.0

by Richard Lobb -
Great catch! Many thanks Luca. A colleague and I had pored over the CodeRunner code looking for plausible explanations for your problem but had drawn a blank. We would certainly never have thought of that!

However, I'd like to better understand the bug, so I know when it will be relevant to me. The $defaultactivityname variable should normally be 'qbank', in which case the code would join only with the qbank table and all would be well, wouldn't it? The only fail case I can see is if the variable $CFG->corequestion_defaultqbankmod has been set to some value other than 'qbank'. Was that the situation on your site?

Thanks again for the debugging effort, saving me from lots more totally fruitless imaginings.

To clarify: