Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-77378

Cloze question where all subquestions have zero weight cause Division by zero errors

XMLWordPrintable

      Here are the steps to replicate the issue:

      1. Create a quiz.
      2. Access its question bank and create a cloze (mutianswer) question with the following text in it:
        Optional question {0:SHORTANSWER:~%0%Input box~%100%*}
      3. Access Questions tab.
      4. Set Maximum grade to 0 and save.
      5. Add the question from question bank.

      Depending on the PHP version you running on the outcome will be different.

      In PHP 8.0 and higher this will throw a Division by zero exception. In PHP 7.4 and older there will be tons of Division by zero warnings on almost every quiz page. In Moodle 4.0 running on PHP 7.4 this will also cause A field with precision 12, scale 7 cannot hold an infinite value exceptions in the \quiz_statistics\task\recalculate task logs, see MDL-77080. This is because randomguessscore field gets set to INF.

      Some extra steps for Moodle 4.0:

      1. Login as a student.
      2. Attempt the quiz.
      3. Andswer the question and finish your attempt.
      4. Run the \quiz_statistics\task\recalculate task and observe the error:

      The \quiz_statistics\task\recalculate task is fixed by MDL-78008

      root@9618166cca87:/var/www/vanilla-moodle-40# php admin/cli/scheduled_task.php --execute='\quiz_statistics\task\recalculate'
      Execute scheduled task: Recalculate question statistics (quiz_statistics\task\recalculate)
      ... started 16:22:56. Current memory use 23.1 MB.
        Examining quiz 'Quiz' (3) in course Test 1 (4) with most recent attempt at 23/02/23, 16:22:49.
          Calculating statistics for 1 attempts, starting at 23/02/23, 16:22:56 ...
       
      Warning: Division by zero in /var/www/vanilla-moodle-40/question/type/multianswer/questiontype.php on line 321
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 301
       
      Warning: Division by zero in /var/www/vanilla-moodle-40/question/type/multianswer/questiontype.php on line 321
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 324
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 328
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 329
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 324
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 328
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 329
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 390
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 394
       
      Warning: A non-numeric value encountered in /var/www/vanilla-moodle-40/question/classes/statistics/questions/calculator.php on line 398
      Error writing to database
       
      ERROR:  numeric field overflow
      DETAIL:  A field with precision 12, scale 7 cannot hold an infinite value.
      INSERT INTO mdl_question_statistics (hashcode,timemodified,questionid,slot,subquestion,s,effectiveweight,negcovar,discriminationindex,discriminativeefficiency,sd,facility,subquestions,maxmark,positions,randomguessscore,variant) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17) 
      [array (
        'hashcode' => '2c8f0869b8a0808e3ca61692d7aaf616938e7e0f',
        'timemodified' => 1677129776,
        'questionid' => '7',
        'slot' => 1,
        'subquestion' => 0,
        's' => 1,
        'effectiveweight' => NULL,
        'negcovar' => 0,
        'discriminationindex' => NULL,
        'discriminativeefficiency' => NULL,
        'sd' => NULL,
        'facility' => NULL,
        'subquestions' => '',
        'maxmark' => '0.0000000',
        'positions' => 1,
        'randomguessscore' => INF,
        'variant' => NULL,
      )]
      Error code: dmlwriteexception
       
      * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
      * line 291 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
      * line 338 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->read_slave_query_end()
      * line 1122 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
      * line 1170 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
      * line 231 of /question/classes/statistics/questions/calculated.php: call to pgsql_native_moodle_database->insert_record()
      * line 259 of /question/classes/statistics/questions/all_calculated_for_qubaid_condition.php: call to core_question\statistics\questions\calculated->cache()
      * line 258 of /question/classes/statistics/questions/calculator.php: call to core_question\statistics\questions\all_calculated_for_qubaid_condition->cache()
      * line 650 of /mod/quiz/report/statistics/report.php: call to core_question\statistics\questions\calculator->calculate()
      * line 941 of /mod/quiz/report/statistics/report.php: call to quiz_statistics_report->get_all_stats_and_analysis()
      * line 105 of /mod/quiz/report/statistics/classes/task/recalculate.php: call to quiz_statistics_report->calculate_questions_stats_for_question_bank()
      * line 253 of /lib/cronlib.php: call to quiz_statistics\task\recalculate->execute()
      * line 167 of /admin/cli/scheduled_task.php: call to cron_run_inner_scheduled_task()
       
      ... used 28 dbqueries
      ... used 0.038141965866089 seconds
      Scheduled task failed: Recalculate question statistics (quiz_statistics\task\recalculate),Error writing to database (ERROR:  numeric field overflow
      DETAIL:  A field with precision 12, scale 7 cannot hold an infinite value.
      INSERT INTO mdl_question_statistics (hashcode,timemodified,questionid,slot,subquestion,s,effectiveweight,negcovar,discriminationindex,discriminativeefficiency,sd,facility,subquestions,maxmark,positions,randomguessscore,variant) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17) 
      [array (
        'hashcode' => '2c8f0869b8a0808e3ca61692d7aaf616938e7e0f',
        'timemodified' => 1677129776,
        'questionid' => '7',
        'slot' => 1,
        'subquestion' => 0,
        's' => 1,
        'effectiveweight' => NULL,
        'negcovar' => 0,
        'discriminationindex' => NULL,
        'discriminativeefficiency' => NULL,
        'sd' => NULL,
        'facility' => NULL,
        'subquestions' => '',
        'maxmark' => '0.0000000',
        'positions' => 1,
        'randomguessscore' => INF,
        'variant' => NULL,
      )])
      Debug info:
      ERROR:  numeric field overflow
      DETAIL:  A field with precision 12, scale 7 cannot hold an infinite value.
      INSERT INTO mdl_question_statistics (hashcode,timemodified,questionid,slot,subquestion,s,effectiveweight,negcovar,discriminationindex,discriminativeefficiency,sd,facility,subquestions,maxmark,positions,randomguessscore,variant) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17) 
      [array (
        'hashcode' => '2c8f0869b8a0808e3ca61692d7aaf616938e7e0f',
        'timemodified' => 1677129776,
        'questionid' => '7',
        'slot' => 1,
        'subquestion' => 0,
        's' => 1,
        'effectiveweight' => NULL,
        'negcovar' => 0,
        'discriminationindex' => NULL,
        'discriminativeefficiency' => NULL,
        'sd' => NULL,
        'facility' => NULL,
        'subquestions' => '',
        'maxmark' => '0.0000000',
        'positions' => 1,
        'randomguessscore' => INF,
        'variant' => NULL,
      )]
      Backtrace:
      * line 291 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
      * line 338 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->read_slave_query_end()
      * line 1122 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
      * line 1170 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
      * line 231 of /question/classes/statistics/questions/calculated.php: call to pgsql_native_moodle_database->insert_record()
      * line 259 of /question/classes/statistics/questions/all_calculated_for_qubaid_condition.php: call to core_question\statistics\questions\calculated->cache()
      * line 258 of /question/classes/statistics/questions/calculator.php: call to core_question\statistics\questions\all_calculated_for_qubaid_condition->cache()
      * line 650 of /mod/quiz/report/statistics/report.php: call to core_question\statistics\questions\calculator->calculate()
      * line 941 of /mod/quiz/report/statistics/report.php: call to quiz_statistics_report->get_all_stats_and_analysis()
      * line 105 of /mod/quiz/report/statistics/classes/task/recalculate.php: call to quiz_statistics_report->calculate_questions_stats_for_question_bank()
      * line 253 of /lib/cronlib.php: call to quiz_statistics\task\recalculate->execute()
      * line 167 of /admin/cli/scheduled_task.php: call to cron_run_inner_scheduled_task()
       
      root@9618166cca87:/var/www/vanilla-moodle-40# 
      

            tomotsuyuki Tomo Tsuyuki
            mikhailgolenkov Misha Golenkov
            Tim Hunt Tim Hunt
            Jun Pataleta Jun Pataleta
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            3 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 33 minutes
                1h 33m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.