KQMATH / moodle-mod_capquiz

:mushroom: Computer adaptive practice activity module for Moodle
https://moodle.org/plugins/mod_capquiz
GNU General Public License v3.0
4 stars 5 forks source link

Cannot delete course containing activity instance #198

Open logan-reynolds opened 3 years ago

logan-reynolds commented 3 years ago

Describe the bug When trying to delete a course containing an instance of the mod_capquiz activity module version 2021021100 release 0.6.0 on Moodle 3.9, course deletion fails with an error message, leaving an empty course that cannot be deleted unless the plugin is completely uninstalled.

To Reproduce Steps to reproduce the behavior:

  1. Go to a test course and add an instance of the mod_capquiz activity module
  2. Go to Site administration -> Courses -> Manage courses and categories and click the trash can icon for the given course containing the activity instance
  3. Confirm deletion of the course
  4. See error

Expected behavior The course should be deleted without encountering any error.

Additional context Error message encountered on the course deletion processing screen is the following:

Can't find data record in database.

More information about this error
Debug info: SELECT cm.*, m.name, md.name AS modname
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module
JOIN {capquiz} m ON m.id = cm.instance

WHERE cm.id = :cmid AND md.name = :modulename

[array (
'cmid' => 1,
'modulename' => 'capquiz',
)]
Error code: invalidrecordunknown
Stack trace:

    line 1627 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
    line 1243 of /lib/datalib.php: call to moodle_database->get_record_sql()
    line 54 of /mod/capquiz/classes/capquiz.php: call to get_coursemodule_from_id()
    line 48 of /mod/capquiz/lib.php: call to mod_capquiz\capquiz->__construct()
    line 5294 of /lib/moodlelib.php: call to capquiz_delete_instance()
    line 5159 of /lib/moodlelib.php: call to remove_course_contents()
    line 68 of /course/delete.php: call to delete_course()

Noting I also get the following error when deleting the activity instance indicating the subplugins file needs to be migrated to the newer format and filename, although this is unrelated to the primary course deletion problem :

Use of subplugins.php has been deprecated. Please update your plugin to provide a subplugins.json file instead.

    line 142 of /lib/adminlib.php: call to debugging()
    line 1515 of /lib/classes/plugin_manager.php: call to uninstall_plugin()
    line 97 of /admin/plugins.php: call to core_plugin_manager->uninstall_plugin()
hgeorgsch commented 3 years ago

Thank you @logan-reynolds for reporting this. Do you happen to know what database backend you use in your installation (mysql? postgres?).

I know we have warnings about SQL statements which may not be cross-db compatible, so we should be aware of this when we reproduce the error.

hgeorgsch commented 3 years ago

I get the same error on our installation (Moodle 3.9 and postgresql 10.16.

hgeorgsch commented 3 years ago

When I attempt to delete the course the CAPQuiz activity disappears but the course becomes undeletable. My guess is that CAPQuiz deletes its activity prematurely, and when the core function tries to do it later, it fails.

erno774 commented 2 years ago

Thank you @logan-reynolds for reporting this. Do you happen to know what database backend you use in your installation (mysql? postgres?).

I know we have warnings about SQL statements which may not be cross-db compatible, so we should be aware of this when we reproduce the error.

Hello hgeorgsch, I've got the same bug on Moodle 3.11.4 with MySQL 5.7.

erno774 commented 1 year ago

I can still confirm this bug on Moodle 4.1 with MariaDB 10.6 and CAPQuiz 0.7.0.