Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Filippo Carnevali -
Number of replies: 6

Hi,

We’re facing an issue with Moodle core activity quiz using core question type multiple choice.

Software version: Moodle 4.1.6+ (Build: 20231020) recently upgraded from 3.9

Server checks: Everything is ok, green as a pasture.

The issue:

Some newly created quizzes (not all quizzes, first headache) break apart when a teacher edit a question in the Questions Bank (eg. edit the body of a question).

Important: question type is a core one and works fine in other quizzes.

Breaking apart in Questions tab and Preview Quiz page.

The “Questions” tab is no longer available responding the following error:

Exception - Argument 1 passed to mod_quiz\question\bank\qbank_helper::get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

Debug info:

Error code: generalexceptionmessage

Stack trace:

line 46 of /mod/quiz/classes/question/bank/qbank_helper.php: TypeError thrown
line 699 of /mod/quiz/classes/structure.php: call to mod_quiz\question\bank\qbank_helper::get_version_options()
line 767 of /mod/quiz/classes/output/edit_renderer.php: call to mod_quiz\structure->get_version_choices_for_slot()
line 545 of /mod/quiz/classes/output/edit_renderer.php: call to mod_quiz\output\edit_renderer->question()
line 518 of /mod/quiz/classes/output/edit_renderer.php: call to mod_quiz\output\edit_renderer->question_row()
line 93 of /mod/quiz/classes/output/edit_renderer.php: call to mod_quiz\output\edit_renderer->questions_in_section()
line 211 of /mod/quiz/edit.php: call to mod_quiz\output\edit_renderer->edit_page()

Preview quiz, on the other hand, respond this after clicking “Start attempt”:

Coding error detected, it must be fixed by a programmer: This question is of a type that is not installed on your system. No processing is possible.

Debug info:

Error code: codingerror

Stack trace:

line 85 of /question/type/missingtype/question.php: coding_exception thrown line 364 of /question/behaviour/behaviourbase.php: call to qtype_missingtype_question->start_attempt() line 1064 of /question/engine/questionattempt.php: call to question_behaviour->init_first_step() line 582 of /question/engine/questionusage.php: call to question_attempt->start() line 257 of /mod/quiz/locallib.php: call to question_usage_by_activity->start_all_questions() line 2690 of /mod/quiz/locallib.php: call to quiz_start_new_attempt() line 113 of /mod/quiz/startattempt.php: call to quiz_prepare_and_start_new_attempt()

And in the browser console:

POST **********/mod/quiz/startattempt.php 404 (Not Found)

It kind of feels like https://tracker.moodle.org/browse/MDL-74452 but it’s a solved issue relevant to older Moodle versions. 

Since I’m not able to reproduce the bug with a step-by-step procedure I don’t feel like commenting on that issue but it’s still a pretty crippling and troublesome situation. 

Does anyone have a clue? 

Thanks!

Average of ratings: -
In reply to Filippo Carnevali

Re: Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Very hard to work ou why this is happening without more information. I wish that error message would tell us what string is being passed where in int is expected.

For what it is worth, the error is coming from this line: https://github.com/moodle/moodle/blob/MOODLE_401_STABLE/mod/quiz/classes/structure.php#L699. So, a few lines above, $this->get_slot_by_number($slotnumber) must have returned something where questionid is not an id.

Are you sure you are on 4.1.6+? Your symptoms seem a lot like MDL-74452, which was fixed in 4.1.3.
In reply to Tim Hunt

Ri: Re: Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Filippo Carnevali -
I'm afraid so, 4.1.6.




Is there a way to see the string passed?

From the server log (php, mysql_error, apache) i'm just receiving the same errors i have in the front-end with debug mode on.
Maybe directly from a table in the database?

Thanks !
In reply to Filippo Carnevali

Re: Ri: Re: Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Miguel González Laredo -
Picture of Plugin developers
Same problem here at Moodle 4.1.4 (Build: 20230612). Any workaround to these issues?

Thanks in advance!
In reply to Miguel González Laredo

Re: Ri: Re: Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
What version of PHP do you see if you go to admin/phpinfo.php

(It probably doesn't matter but it might be useful to know)
In reply to Marcus Green

Re: Ri: Re: Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Miguel González Laredo -
Picture of Plugin developers

Exactly --> PHP Version 8.1.29

Keep obtaining the same problem on several circumstances...

In reply to Filippo Carnevali

Re: Issue get_version_options() must be of the type int, string given, called in [dirroot]/mod/quiz/classes/structure.php on line 699

by Kevin B -

In my case, the error occurred here:

line 699 of /mod/quiz/classes/structure.php: call to mod_quiz\question\bank\qbank_helper::get_version_options()

Since this function accepts integers, I modified the code

from:

$versions = qbank_helper::get_version_options($slot->questionid);

to:

$versions = qbank_helper::get_version_options( intval($slot->questionid) );

I don't know if it was the best solution, but it worked for me.

Average of ratings: Useful (1)