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

Course module cache is cleared after event is triggered causes issues for event observers

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.5.5, 5.0
    • Caching, Course
    • MOODLE_405_STABLE, MOODLE_500_STABLE
    • MDL-85419-main
    • Hide
      1. Create a plugin that has an event observer for course_module_updated and checks the $cm->visible property
      2. Create an activity
      3. Hide the activity
        1. The event observer should pick up that the $cm->visible is set to zero
      Show
      Create a plugin that has an event observer for course_module_updated and checks the $cm->visible property Create an activity Hide the activity The event observer should pick up that the $cm->visible is set to zero
    • Hide

      Code verified against automated checks.

      Checked MDL-85419 using repository: https://github.com/sharpchi/moodle/

      More information about this report

      Built on: Tue May 20 08:06:35 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-85419 using repository: https://github.com/sharpchi/moodle/ main (0 errors / 0 warnings) [branch: MDL-85419-main | CI Job ] More information about this report Built on: Tue May 20 08:06:35 UTC 2025

      I have an event observer for course_module_updated which checks the visibility. When the event is triggered I use `get_course_and_cm_from_cmid()` to get the cached course module.

      Trouble is MDL-79615 allows for deferral of clearing the cache for bulk actions, and where this option is being used, the events are triggered before the cache is cleared. e.g https://github.com/moodle/moodle/blob/15b534da3ede9c3966f994e965ecac7361a21b7f/course/format/classes/stateactions.php#L502 

      This results in event observers like mine getting the wrong data from cache.

      In these instances could we move the triggers until after the cache has been cleared?

            sharpchi Mark Sharp
            sharpchi Mark Sharp
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 30 minutes
                30m

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