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

The get_completion_data method of the completion_info class can return invalid data.

XMLWordPrintable

    • MOODLE_405_STABLE, MOODLE_500_STABLE
    • Hide

      This error is buried deep and difficult to test manually:

      Setup in Moodle Workplace:

      1. Create a test user
      2. Create a test program
      3. Create a certificate for the test program
      4. Create a test course for the test program
      5. Associate the course with the program
      6. Create two test modules for the test course
      7. Set one of the test module to require view for completion
      8. Set the course recertification delay to 1 day

      Test:

      1. Use the test user to view the test module in the test course.
      2. Delete the completion data (but not the viewed data!).
        1. This can be done manually in the database
        2. Or it can be done using the MDL-83946 bug by editing completion requirements for the course.
      3. Change the completion date to be at least a day ago so you don't have to wait.
      4. Run the recertification scheduled task.
        1. You should get a fatal error before patch and the task should complete after patch.

      Simplified testing:

      1. Run the updated unit tests for get_completion_data in the lib/tests/completionlib_test.php
        1. The unit tests now check for null values for completiondate so it will fail without the patch for this issue or MDL-83946.
      Show
      This error is buried deep and difficult to test manually: Setup in Moodle Workplace: Create a test user Create a test program Create a certificate for the test program Create a test course for the test program Associate the course with the program Create two test modules for the test course Set one of the test module to require view for completion Set the course recertification delay to 1 day Test: Use the test user to view the test module in the test course. Delete the completion data (but not the viewed data!). This can be done manually in the database Or it can be done using the MDL-83946 bug by editing completion requirements for the course. Change the completion date to be at least a day ago so you don't have to wait. Run the recertification scheduled task. You should get a fatal error before patch and the task should complete after patch. Simplified testing: Run the updated unit tests for get_completion_data in the lib/tests/completionlib_test.php The unit tests now check for null values for completiondate so it will fail without the patch for this issue or MDL-83946 .
    • Hide

      Code verified against automated checks.

      Checked MDL-83961 using repository: https://github.com/tbannister/moodle

      More information about this report

      Built on: Tue 10 Dec 2024 04:46:40 PM UTC

      Show
      Code verified against automated checks. Checked MDL-83961 using repository: https://github.com/tbannister/moodle main (0 errors / 0 warnings) [branch: MDL-83961 | CI Job ] More information about this report Built on: Tue 10 Dec 2024 04:46:40 PM UTC

      In certain situations, the get_completion_data method of the completion_info class can return data which can not be inserted into the completion data table. 

      Specifically, if a record exists in the course_modules_viewed table but not in the course_modules_completion table then the get_completion_data method will return an array where completionstate and timemodified are both null.  The course_modules_completion table definition does not allow either of those columns to be null.

      The functional impact is that because the database table definition doesn't allow either those values to be null, any code that naively updates the value returned by the get_completion_data method (or the get_data method because it calls get_completion_data and also returns that value) and then tries to save the updated value will trigger a fatal database error.

      In practice, this problem can occur with the Moodle Workplace course_reset_api where the reset_module_viewed method updates the viewed status of the returned data and attempts to save the result without confirming that the completionstate and timemodified columns have valid data.

      Note: The bug outlined in MDL-83946 is one way for viewed records to exist without matching completion records.

            Unassigned Unassigned
            tbannister Tyler Bannister
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 minutes
                3m

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