Moodle
  1. Moodle
  2. MDL-34532

Error on selecting different attempts for quiz reports

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.3.2
    • Component/s: Quiz
    • Labels:
    • Testing Instructions:
      Hide

      1. Got to the quiz reports for a quiz with some students who have attempted the quiz and some who have not.

      2. View the report including students who have not attempted the quiz. Verify there are no errors.

      Show
      1. Got to the quiz reports for a quiz with some students who have attempted the quiz and some who have not. 2. View the report including students who have not attempted the quiz. Verify there are no errors.
    • Affected Branches:
      MOODLE_24_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      42959

      Description

      Noticed the error while testing MDL-34468. This issue might be related to MDL-34164.

      To reproduce:
      1. Review quiz attempt.
      2. change the attempts to other value other than the pre-selected.
      3. select the show report button.

      It produces the following error:

      Debug info:
      Error code: codingerror
      Stack trace:
      
          line 846 of /mod/quiz/locallib.php: coding_exception thrown
          line 516 of /mod/quiz/attemptlib.php: call to quiz_attempt_state_name()
          line 155 of /mod/quiz/report/attemptsreport_table.php: call to quiz_attempt::state_name()
          line 703 of /lib/tablelib.php: call to quiz_attempts_report_table->col_state()
          line 1271 of /lib/tablelib.php: call to flexible_table->format_row()
          line 66 of /mod/quiz/report/overview/overview_table.php: call to table_sql->build_table()
          line 1383 of /lib/tablelib.php: call to quiz_overview_table->build_table()
          line 236 of /mod/quiz/report/overview/report.php: call to table_sql->out()
          line 100 of /mod/quiz/report.php: call to quiz_overview_report->display()
      

        Issue Links

          Activity

          Hide
          Ankit Agarwal added a comment -

          The error is produced because state of the state of attempt being not set. Am not sure where the state get's lost, but it was not set in the col_state() call.

          This issue seems to be introduced by some changes this week, as this is working on stable master but not on integration master.
          Thanks

          Show
          Ankit Agarwal added a comment - The error is produced because state of the state of attempt being not set. Am not sure where the state get's lost, but it was not set in the col_state() call. This issue seems to be introduced by some changes this week, as this is working on stable master but not on integration master. Thanks
          Hide
          Tim Hunt added a comment -

          I'm completely baffled how anyone thinks this could be related to MDL-34351, which only adding a try-catch block in mod/quiz/cronlib.php.

          And I have followed "git log -p mod/quiz" back to mid-June, and cannot see anything that might cause this.

          That exception throw comes from quiz_attempt_state_name in locallib.php which does a switch on state, then throws an exception if the value is not recognised.

          quiz DB upgrade script that added the question_attempts.state column (2012040203 and 2012040204 blocks) adds the column with default 'inprogress', and then updates some of those to be 'finished', so no chance of bad values initially.

          So, the other option is that the SQL is not loading these values. The call comes from col_state in mod/quiz/report/attemptsreport_table.php. $attempt->state is loaded by some complex SQL that is constructed in mod/quiz/report/attemptsreport_table.php in base_sql. That does include the state column.

          I need more information. Those who are seeing this problem, can you check:

          1. This query should return no rows, what does it return for you?

          SELECT * FROM mdl_quiz_attempts WHERE state NOT IN ('inprogress', 'finished', 'abandoned', 'overdue')

          2. Capture the SQL that the report is actually running (you will need to add debug code in query_db in lib/tablelib.php. At the end, output $sql and $this->sql->params. Is the query correctly fetching the state column?

          Thanks.

          Show
          Tim Hunt added a comment - I'm completely baffled how anyone thinks this could be related to MDL-34351 , which only adding a try-catch block in mod/quiz/cronlib.php. And I have followed "git log -p mod/quiz" back to mid-June, and cannot see anything that might cause this. That exception throw comes from quiz_attempt_state_name in locallib.php which does a switch on state, then throws an exception if the value is not recognised. quiz DB upgrade script that added the question_attempts.state column (2012040203 and 2012040204 blocks) adds the column with default 'inprogress', and then updates some of those to be 'finished', so no chance of bad values initially. So, the other option is that the SQL is not loading these values. The call comes from col_state in mod/quiz/report/attemptsreport_table.php. $attempt->state is loaded by some complex SQL that is constructed in mod/quiz/report/attemptsreport_table.php in base_sql. That does include the state column. I need more information. Those who are seeing this problem, can you check: 1. This query should return no rows, what does it return for you? SELECT * FROM mdl_quiz_attempts WHERE state NOT IN ('inprogress', 'finished', 'abandoned', 'overdue') 2. Capture the SQL that the report is actually running (you will need to add debug code in query_db in lib/tablelib.php. At the end, output $sql and $this->sql->params. Is the query correctly fetching the state column? Thanks.
          Hide
          Ankit Agarwal added a comment -

          Hi Tim,

          1.MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0001 sec )
          2.

          SELECT CONCAT(u.id, '#', COALESCE(quiza.attempt, 0)) AS uniqueid, quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.institution, u.department, u.email, quiza.state, quiza.sumgrades, quiza.timefinish, quiza.timestart, CASE WHEN quiza.timefinish = 0 THEN null WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart ELSE 0 END AS duration, COALESCE(( SELECT MAX(qqr.regraded) FROM {quiz_overview_regrades} qqr WHERE qqr.questionusageid = quiza.uniqueid ), -1) AS regraded FROM {user} u LEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid WHERE u.id IN (:u16,:u17,:u18) AND quiza.id IS NULL ORDER BY quiza.id ASC
          
          

          3. when the first option is selected it works fine. The error is produced when any other option beside the default one is selected.
          The query for the default option is :-

          SELECT CONCAT(u.id, '#', COALESCE(quiza.attempt, 0)) AS uniqueid, quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.institution, u.department, u.email, quiza.state, quiza.sumgrades, quiza.timefinish, quiza.timestart, CASE WHEN quiza.timefinish = 0 THEN null WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart ELSE 0 END AS duration, COALESCE(( SELECT MAX(qqr.regraded) FROM {quiz_overview_regrades} qqr WHERE qqr.questionusageid = quiza.uniqueid ), -1) AS regraded FROM {user} u LEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid WHERE u.id IN (:u16,:u17,:u18) AND quiza.preview = 0 AND quiza.id IS NOT NULL ORDER BY quiza.id ASC
          

          Thanks

          Show
          Ankit Agarwal added a comment - Hi Tim, 1.MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0001 sec ) 2. SELECT CONCAT(u.id, '#', COALESCE(quiza.attempt, 0)) AS uniqueid, quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.institution, u.department, u.email, quiza.state, quiza.sumgrades, quiza.timefinish, quiza.timestart, CASE WHEN quiza.timefinish = 0 THEN null WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart ELSE 0 END AS duration, COALESCE(( SELECT MAX(qqr.regraded) FROM {quiz_overview_regrades} qqr WHERE qqr.questionusageid = quiza.uniqueid ), -1) AS regraded FROM {user} u LEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid WHERE u.id IN (:u16,:u17,:u18) AND quiza.id IS NULL ORDER BY quiza.id ASC 3. when the first option is selected it works fine. The error is produced when any other option beside the default one is selected. The query for the default option is :- SELECT CONCAT(u.id, '#', COALESCE(quiza.attempt, 0)) AS uniqueid, quiza.uniqueid AS usageid, quiza.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.institution, u.department, u.email, quiza.state, quiza.sumgrades, quiza.timefinish, quiza.timestart, CASE WHEN quiza.timefinish = 0 THEN null WHEN quiza.timefinish > quiza.timestart THEN quiza.timefinish - quiza.timestart ELSE 0 END AS duration, COALESCE(( SELECT MAX(qqr.regraded) FROM {quiz_overview_regrades} qqr WHERE qqr.questionusageid = quiza.uniqueid ), -1) AS regraded FROM {user} u LEFT JOIN {quiz_attempts} quiza ON quiza.userid = u.id AND quiza.quiz = :quizid WHERE u.id IN (:u16,:u17,:u18) AND quiza.preview = 0 AND quiza.id IS NOT NULL ORDER BY quiza.id ASC Thanks
          Hide
          Tim Hunt added a comment -

          OK, so all that looks like it is working as expected.

          Can you run the other queries, and see if they are returning any bad data in the ...

          Ah! I have worked it out. When you are showing users without attempts, state will be NULL, and that causes the exception throw. Will fix.

          Show
          Tim Hunt added a comment - OK, so all that looks like it is working as expected. Can you run the other queries, and see if they are returning any bad data in the ... Ah! I have worked it out. When you are showing users without attempts, state will be NULL, and that causes the exception throw. Will fix.
          Hide
          Aparup Banerjee added a comment -

          The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

          TIA and ciao

          Show
          Aparup Banerjee added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
          Hide
          Dan Poltawski added a comment -

          I've integrated this now, thanks Tim

          Show
          Dan Poltawski added a comment - I've integrated this now, thanks Tim
          Hide
          Ankit Agarwal added a comment -

          working as expected!
          Passing!
          Thanks

          Show
          Ankit Agarwal added a comment - working as expected! Passing! Thanks
          Hide
          Dan Poltawski added a comment -

          asko, Дзякуй, ধন্যবাদ, Благодаря, Gràcies, 感谢, 謝謝, Hvala, Díky, Tak, Bedankt, Tänan, متشکریم, Salamat, Kiitokset, Merci, Grazas, Danke, Ευχαριστώ, આભાર, תודה, धन्यवाद, Köszönjük, Takk fyrir, Terima Kasih, Grazie, ありがとうございます, Рахмет, សូមអរគុណ, 감사합니다, gratiās, Pateicamies, Ačiū, Благодарам, Tēnā koa, Kia Ora Rawa Atu, आभारी आहोत, Талархал, Takk, Dziękuję, Obrigado, Mulţumesc, Engraziel, Спасибо, Fa'afetai, Хвала, Hvala, ස්තූතියි, Vďaka, Hvala, Mahadsanid, Thanks, Gracias, Tack, Salamat, நன்றி, నెనరులు, ขอบคุณค่ะ!

          Your work has made it into this weeks Moodle release! There are no gold medals available this week - but millions around the world will benefit. Thank you!

          Show
          Dan Poltawski added a comment - asko, Дзякуй, ধন্যবাদ, Благодаря, Gràcies, 感谢, 謝謝, Hvala, Díky, Tak, Bedankt, Tänan, متشکریم, Salamat, Kiitokset, Merci, Grazas, Danke, Ευχαριστώ, આભાર, תודה, धन्यवाद, Köszönjük, Takk fyrir, Terima Kasih, Grazie, ありがとうございます, Рахмет, សូមអរគុណ, 감사합니다, gratiās, Pateicamies, Ačiū, Благодарам, Tēnā koa, Kia Ora Rawa Atu, आभारी आहोत, Талархал, Takk, Dziękuję, Obrigado, Mulţumesc, Engraziel, Спасибо, Fa'afetai, Хвала, Hvala, ස්තූතියි, Vďaka, Hvala, Mahadsanid, Thanks, Gracias, Tack, Salamat, நன்றி, నెనరులు, ขอบคุณค่ะ! Your work has made it into this weeks Moodle release! There are no gold medals available this week - but millions around the world will benefit. Thank you!
          Hide
          Tim Hunt added a comment -

          The error message is:

          Coding error detected, it must be fixed by a programmer: Unknown quiz attempt state.

          Just adding that so searching finds this.

          Show
          Tim Hunt added a comment - The error message is: Coding error detected, it must be fixed by a programmer: Unknown quiz attempt state. Just adding that so searching finds this.

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: