Adding section heading in quiz causes error message

Adding section heading in quiz causes error message

by Antonia Bonaccorso -
Number of replies: 11
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

We encountered a strange behaviour of Moodle 3.0.4+ when trying to add section headings to quizzes and wondered, whether anyone encountered the same behaviour or has any idea how to solve it.


When having the last 3 questions of a quiz with at least 12 questions on the same page and trying to add a section heading to these 3 last questions on the same page, the section heading was not created. When we turned debugging on, we received the error message attached. If we then went back to the quiz and tried to add the section heading to the last three questions on the same page again, the section heading was created without any error message appearing.


We did some further testing which revealed that

- The error message occurs with different kinds of question types

- We could sometimes but not always reproduce the behaviour with quizzes with 11 questions

- We could never reproduce the behaviour with quizzes with 10 or less questions

- We could reproduce the behaviour when adding section headings to pages with several questions in the middle of the quiz AS LONG AS the page contained question number 10


To us it seems that there is a problem with the shift from single-digit question numbers to double-digit question numbers.


Did anyone else encounter the same or a similar behaviour? Has anyone an idea how to solve the problem?

 

Cheers,

Antonia and Kristina
Average of ratings: -
In reply to Antonia Bonaccorso

Re: Adding section heading in quiz causes error message

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Did you remember to attache the error message? I can't see it.

Is it the same as the one in MDL-57228?

In reply to Tim Hunt

Re: Adding section heading in quiz causes error message

by Antonia Bonaccorso -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Thanks for the reminder regarding the error message, Tim. It is now attached.


I had a look at MDL-57228. As fas as I can see it is not the same issue even though both issues have the same error code dmlwriteexception. The error message we got states that there is a violation of not-null constraint whereas the error message for MDL-57228 states there is a unique key violation.


I also had a look at the corresponding forum post 343696. According to the forum post MDL-57228 only occurs when "Attempting to add questions to a quiz in a course that has been restored from a previous course". However, the behaviour we detected also happens with newly created questions - be they created directly via quiz or in the question bank and then added to a quiz.


Cheers,

Antonia

Attachment 12_new_questions_3on1page_end.PNG
In reply to Antonia Bonaccorso

Re: Adding section heading in quiz causes error message

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Right. It is a different error. firstslot definitely should not be NULL. I wonder how that is happening? I'm pretty sure I have never seen that error before. Still, it might be worth trying an upgrade to Moodle 3.0.7, in case that fixes it.

Can you reproduce the problem at qa.moodle.net? Can you reprouce the problem starting with a new empty quiz and adding things one at a time?

In reply to Tim Hunt

Re: Adding section heading in quiz causes error message

by Antonia Bonaccorso -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I could reproduce the error message (see attachement) on qa.moodle.net when adding all 12 questions at once from question bank to a new empty quiz, putting question 10, 11 and 12 on the same page and trying to add a section heading to this page.

I did not manage to reproduce the error message on qa.moodle.net when adding 12 questions one after the other directly to a new empty quiz, putting question 10, 11 and 12 on the same page and trying to add a section heading to this page.

As qa.moodle.net is reset every hour I also attached a screenshot of the quiz I created.

Attachment error_message_on_qa.PNG
Attachment test_quiz_on_qa.PNG
In reply to Antonia Bonaccorso

Re: Adding section heading in quiz causes error message

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I have just failed to reproduce this. Can you be exact on how you are "putting question 10, 11 and 12 on the same page".

The line of code where it is going wrong is https://github.com/moodle/moodle/blob/master/mod/quiz/classes/structure.php#L1003. And, that must be because the DB query on the line before is returning no data, which suggests $pageid is wrong. (Hmm. those two lines of code to set ->firstslot look decidedly non-optimal anyway.) Also, the hard-coded string in the function parameters is bad.

In reply to Tim Hunt

Re: Adding section heading in quiz causes error message

by Antonia Bonaccorso -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I have just failed to reproduce this. Can you be exact on how you are "putting question 10, 11 and 12 on the same page".

  1. I added all questions to the quiz.
  2. I clicked the double-arrow-icon (marked in yellow on the screenshot attached) on the left between question 10 and 11 --> they are on the same page now.
  3. I clicked the double-arrow-icon on the left between question 11 and 12 --> question 12 is now on the same page as question 10 and 11.
  4. I tried to add the section heading by clicking on "Add section heading".
Remark: I could also reproduce it, when moving two questions from the middle of the quiz directly to the last page so that there were three questions on the last page.


Attachment test_quiz_on_qa.PNG
In reply to Antonia Bonaccorso

Re: Adding section heading in quiz causes error message

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry to be dense, but I am still failing to reproduce this. Can you fill in any of the gaps or questions in the following:

  1. I am on https://qa.moodle.net/course/view.php?id=7 -- I am guessing it is that course from the screen grab.
  2. Turn editing on.
  3. Add new quiz.
  4. Click Edit quiz button.
  5. Click Add -> From question bank.
  6. Click Select all -- hang on, there are no questions in the question bank for the course. Where do the questions come from?
  7. Click Add selected questions to quiz.
  8. Click the double arrow icon between Qs 10 and 11
  9. Click the double arrow icon between Qs 11 and 12
  10. Click Add -> Section heading for Page ???

Is that right?

Which web browser are you using? Are there any errors in the JavaScript console as you follow these steps?

In reply to Tim Hunt

Re: Adding section heading in quiz causes error message

by Antonia Bonaccorso -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
1.  Yes, I tested in the Moodle course  "Course Fullname 101" (course id = 7).
2. trhough 4. were also my next steps.
5. I then went to the question bank for this specific quiz by clicking the gear-wheel icon and selecting question bank from the drop-down-menu  and created all 12 questions one after the other. Note 1: I did NOT copy the questions but create each one individually. Note 2: I could also reproduce if questions were in the default category for the course.
6. Click Add -> From question bank.
7. Click Select all --> now there are 12 questions in the question bank.
8. Click Add selected questions to quiz.
9. Click the double arrow icon between Qs 10 and 11
10. Click the double arrow icon between Qs 11 and 12
11. Click Add -> Section heading for Page 10 (the last page with questions 10 through 12 (see screenshot in my message from today morning))

So your process was just about right with step 5 "creating questions in question bank" missing.

I'm using Firefox Version 50.0.2 - which is the newest version.

If you could explain to me how to use the JavaScript console I can have I look whether I get any errors during this process.



In reply to Antonia Bonaccorso

Re: Adding section heading in quiz causes error message

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yay! I managed to reproduce it. Thank you for your patience.

It is acutally enough just to combine questions 11 and 12.

The problem is that it ends up making a request

.../mod/quiz/edit.php?cmid=977&addsectionatpage=111

And, obviously, that 111 is wrong.

After clicking the double-arrow button, the JavaScript code has to update all the links in the page. Clearly that is going wrong. I will dig further.

In reply to Tim Hunt

Re: Adding section heading in quiz causes error message

by Antonia Bonaccorso -
Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Thanks for your patience, too. And also thanks for digging further!