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

Course delete modules: Throw an exception if the course module has an instance of zero

XMLWordPrintable

    • 2
    • Team Hedgehogs 2025 Sprint 2.0, Team Hedgehogs 2025 Sprint 2.1

      I'm not sure if that's legit for course module to have zero instance, but we're facing failing course_delete_modules adhoc tasks quite often due to this issue.

      Task log:

      Execute adhoc task: core_course\task\course_delete_modules
      Adhoc task id: 181318323
      Adhoc task custom data: {"cms":{"10476298":{"id":"10476298"}},"userid":"503662","realuserid":"503662"}
      ... started 09:34:33. Current memory use 127.2MB.
      Debugging increased temporarily due to faildelay of 61440
      ... used 20 dbqueries
      ... used 0.07473611831665 seconds
      Adhoc task failed: core_course\task\course_delete_modules,Coding error detected, it must be fixed by a programmer: The course module 10476298 could not be deleted. error/cannotdeletemoduleinstance: /var/www/site/course/lib.php(1055) #0 /var/www/site/course/classes/task/course_delete_modules.php(66): course_delete_module('10476298')
      #1 /var/www/site/lib/cronlib.php(359): core_course\task\course_delete_modules->execute()
      #2 /var/www/site/lib/cronlib.php(198): cron_run_inner_adhoc_task(Object(core_course\task\course_delete_modules))
      #3 /var/www/site/admin/cli/adhoc_task.php(131): cron_run_adhoc_tasks(1654126431, 60, true)
      #4 {main}
      Backtrace:
      * line 359 of /lib/cronlib.php: call to core_course\task\course_delete_modules->execute()
      * line 198 of /lib/cronlib.php: call to cron_run_inner_adhoc_task()
      * line 131 of /admin/cli/adhoc_task.php: call to cron_run_adhoc_tasks()
      

      /var/www/site/course/lib.php(1055) is this line: https://github.com/moodle/moodle/blob/05087afd40ea642f339792a2d5335086a1d1d4f7/course/lib.php#L1055

      Course module record:

      moodle=# SELECT m.name, cm.instance, cm.added FROM mdl_course_modules cm, mdl_modules m WHERE cm.module = m.id AND cm.id = 10476298;
       name  | instance |   added    
      -------+----------+------------
       label |        0 | 1436938217
      (1 row)
      

      Despite old timestamp this seems to be a recently created/restored from a backup course.

        1. testadhoc_MDL-74900.php
          2 kB
          Raquel Ortega
        2. MDL-74900.png
          521 kB
          Ron Carl Alfon Yu

            raquel.ortega@moodle.com Raquel Ortega
            mikhailgolenkov Misha Golenkov
            David Woloszyn David Woloszyn
            Huong Nguyen Huong Nguyen
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            4 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 4 hours, 54 minutes
                1d 4h 54m

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