Coding error detected, it must be fixed by a programmer: There is no question_attempt number in this attempt.

Coding error detected, it must be fixed by a programmer: There is no question_attempt number in this attempt.

by Matt Rice -
Number of replies: 3

Pretty much what it says in the subject: I noticed some error messages popping up in the cron log (I do not know for how long they have been there), but I would like to get it fixed, if possible. Some assistance would be appreciated!


Processing module function quiz_cron ...

  Looking for quiz overdue quiz attempts...
PHP Notice:  Undefined offset: 450821 in /var/moodle/mod/quiz/attemptlib.php on line 668

Notice: Undefined offset: 450821 in /var/moodle/mod/quiz/attemptlib.php on line 668
PHP Notice:  Trying to get property of non-object in /var/moodle/mod/quiz/attemptlib.php on line 668

Notice: Trying to get property of non-object in /var/moodle/mod/quiz/attemptlib.php on line 668
PHP Warning:  Creating default object from empty value in /var/moodle/mod/quiz/attemptlib.php on line 673

Warning: Creating default object from empty value in /var/moodle/mod/quiz/attemptlib.php on line 673
Error while processing attempt 235954 at 15583 quiz:
Coding error detected, it must be fixed by a programmer: There is no question_attempt number 450821 in this attempt.
#0 /var/moodle/question/engine/questionusage.php(277): question_usage_by_activity->check_slot('450821')
#1 /var/moodle/question/engine/questionusage.php(224): question_usage_by_activity->get_question_attempt('450821')
#2 /var/moodle/mod/quiz/attemptlib.php(1128): question_usage_by_activity->get_question('450821')
#3 /var/moodle/mod/quiz/attemptlib.php(686): quiz_attempt->is_real_question('450821')
#4 /var/moodle/mod/quiz/attemptlib.php(575): quiz_attempt->number_questions()
#5 /var/moodle/mod/quiz/cronlib.php(78): quiz_attempt->__construct(Object(stdClass), Object(stdClass), Object(stdClass), Object(stdClass))
#6 /var/moodle/mod/quiz/lib.php(535): mod_quiz_overdue_attempt_updater->update_overdue_attempts(1499962922, 1499962862)
#7 /var/moodle/lib/classes/task/legacy_plugin_cron_task.php(93): quiz_cron()
#8 /var/moodle/lib/cronlib.php(75): core\task\legacy_plugin_cron_task->execute()
#9 /var/moodle/admin/cli/cron.php(61): cron_run()
#10 {main}
  Considered 0 attempts in 1 quizzes.


Some followup sleuthing:

This quiz appears in a course from 2012.

SELECT * FROM mdl_quiz WHERE id = 15583\G
*************************** 1. row ***************************
                         id: 15583
                     course: 10015
                       name: QUIZ # 8 (4.2 - 4.4)
                      intro:
                introformat: 1
                   timeopen: 1339502400
                  timeclose: 1340139600
         preferredbehaviour: deferredfeedback
           canredoquestions: 0
                   attempts: 1
              attemptonlast: 0
                grademethod: 3
              decimalpoints: 2
      questiondecimalpoints: -1
              reviewattempt: 69904
          reviewcorrectness: 69904
                reviewmarks: 69904
     reviewspecificfeedback: 69648
      reviewgeneralfeedback: 69648
          reviewrightanswer: 16
      reviewoverallfeedback: 4096
           questionsperpage: 10
             shuffleanswers: 1
                  sumgrades: 10.00000
                      grade: 10.00000
                timecreated: 0
               timemodified: 1339459714
                  timelimit: 0
            overduehandling: autoabandon
                graceperiod: 0
                   password:
                     subnet:
            browsersecurity: -
                     delay1: 0
                     delay2: 0
            showuserpicture: 0
                 showblocks: 0
completionattemptsexhausted: 0
             completionpass: 0
                  navmethod: free


SELECT * FROM mdl_quiz_attempts WHERE id = 235954\G
*************************** 1. row ***************************
            id: 235954
      uniqueid: 235954
          quiz: 15583
        userid: 16116
       attempt: 1
     sumgrades: 0.00000
     timestart: 1339509684
    timefinish: 0
  timemodified: 1339509684
timecheckstate: 1340139600
        layout: 5,1,6,450821,8,2,7,4,3,9,0
       preview: 0
         state: inprogress
   currentpage: 0


If I visit the quiz attempt itself (requires authentication, mostly linking for myself later), I get a similar error:


Coding error detected, it must be fixed by a programmer: There is no question_attempt number 450821 in this attempt.

More information about this error

Debug info: 
Error code: codingerror
Stack trace:
  • line 263 of /question/engine/questionusage.php: coding_exception thrown
  • line 277 of /question/engine/questionusage.php: call to question_usage_by_activity->check_slot()
  • line 224 of /question/engine/questionusage.php: call to question_usage_by_activity->get_question_attempt()
  • line 1128 of /mod/quiz/attemptlib.php: call to question_usage_by_activity->get_question()
  • line 686 of /mod/quiz/attemptlib.php: call to quiz_attempt->is_real_question()
  • line 575 of /mod/quiz/attemptlib.php: call to quiz_attempt->number_questions()
  • line 593 of /mod/quiz/attemptlib.php: call to quiz_attempt->__construct()
  • line 603 of /mod/quiz/attemptlib.php: call to quiz_attempt::create_helper()
  • line 45 of /mod/quiz/review.php: call to quiz_attempt::create()
Output buffer: Notice: Undefined offset: 450821 in /var/moodle/mod/quiz/attemptlib.php on line 668 Notice: Trying to get property of non-object in /var/moodle/mod/quiz/attemptlib.php on line 668 Warning: Creating default object from empty value in /var/moodle/mod/quiz/attemptlib.php on line 673

Moodle 3.1.2 (Build: 20160912)

Moodle mod_quiz version 2016052300

Average of ratings: -
In reply to Matt Rice

Re: Coding error detected, it must be fixed by a programmer: There is no question_attempt number in this attempt.

by Matt Rice -

From what I can tell, the issue seems to lie with the `mdl_quiz_attempts`.`layout` field: all the other mdl_quiz_attempts have a layout that runs from 0-9 (randomized order). I could probably post another record for the same quiz, if it were helpful.


I do not know what version of Moodle (1.9?) or mod_quiz (no idea) we were running back in 2012.

In reply to Matt Rice

Re: Coding error detected, it must be fixed by a programmer: There is no question_attempt number in this attempt.

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

You are right to focus on that anomalous id.

Your guess about 1.9 is one idea. This could be an attempt made in a version of Moodle older than 2.1, and something went wrong during the upgrade.

The other possible explanation is similar: it could have come from restoring an old quiz attempt.

I can see a few options for dealing with this - most of which assume that you don't need this quiz attempt any more:

  • You could try deleting it using the option in the  Quiz results report. (This will either work or give the same error.)
  • You could try editing directly in the database. Remove '450821,' from '5,1,6,450821,8,2,7,4,3,9,0'.
  • ... etc.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Coding error detected, it must be fixed by a programmer: There is no question_attempt number in this attempt.

by Matt Rice -

I tried directly editing the layout field in the database (removing '450821,' as suggested); this appears to have cleared up both the error in the cron and the error on the page itself.

Interestingly enough, now that that record is not causing an error, it is marked as state = 'abandoned', so double confirmation that cron was able to process it.

Thanks for the nudge, Tim!