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

Error Writing to Database During Course Reset After Upgrade to 2.x

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.0.3
    • Fix Version/s: None
    • Component/s: Backup, Course
    • Database:
      Any
    • Testing Instructions:
      Hide

      On a 1.9 site that includes modules not yet supported in 2.x, upgrade the site to 2.x. The modules with which we had problems were mod/kaltura and mod/extrafeatures. mod/wiziq and mod/wwwbdashboard caused a different but similar error due to the 'course' field not existing in their tables. After the upgrade, try to reset a course. If you get the error, it will be right after clicking Reset in the course's settings block. With the patch in place, you won't get an error and will be able to reset the course.

      If you don't get the error because you don't have any plugins with non-existent tables, you can simulate the same problem by just deleting (on a test site!) the table for any installed module. It will throw the same error since the table doesn't exist.

      Show
      On a 1.9 site that includes modules not yet supported in 2.x, upgrade the site to 2.x. The modules with which we had problems were mod/kaltura and mod/extrafeatures. mod/wiziq and mod/wwwbdashboard caused a different but similar error due to the 'course' field not existing in their tables. After the upgrade, try to reset a course. If you get the error, it will be right after clicking Reset in the course's settings block. With the patch in place, you won't get an error and will be able to reset the course. If you don't get the error because you don't have any plugins with non-existent tables, you can simulate the same problem by just deleting (on a test site!) the table for any installed module. It will throw the same error since the table doesn't exist.
    • Affected Branches:
      MOODLE_20_STABLE
    • Pull Master Branch:
      MDL-28963_Error_Writing_DB

      Description

      After upgrading a site to 2.x, an admin or teacher may receive an error, "Error writing to database," when attempting to reset a course. course/reset_form.php grabs a list of all modules from mdl_modules and then loops over them to count instances of each in the course. When a table with the module name doesn't exist or the table doesn't contain the expected 'course' field, an exception is thrown and the user receives an error. Expected behavior is to not receive an error and be able to reset the course.

      We tracked this down to the site having been upgraded from 1.9 to 2.0 and still having records in mdl_modules for modules that existed in 1.9 but haven't been updated for 2.0. To prevent the error and allow the user to reset the course, the simplest fix seems to be to wrap if (!$DB->count_records()) with a try/catch to catch the exception and continue to the next module. A patch is attached for that.

        Attachments

        1. lib_moodlelib2.patch
          2 kB
        2. reset_form_2.patch
          2 kB
        3. reset_form.patch
          1 kB

          Issue Links

            Activity

              People

              Assignee:
              skodak Petr Skoda
              Reporter:
              cfollin Chris Follin
              Peer reviewer:
              Ankit Agarwal Ankit Agarwal
              Integrator:
              Aparup Banerjee Aparup Banerjee
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: