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

Cannot find data record in database table course for course completion when the course required has been deleted

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.7.1, 3.7.2, 3.8
    • Fix Version/s: None
    • Component/s: Course completion
    • Labels:
    • Affected Branches:
      MOODLE_37_STABLE, MOODLE_38_STABLE

      Description

      This issue has been raised previously under MDL-40081 but was unable to be reproduced and was discussed by people experiencing it here https://moodle.org/mod/forum/discuss.php?d=387180 

      Steps to reproduce.

      Normal operation 

      • Go to course with Course Completion enabled. 
      • Go to course completion screen 
      • Mark activities that need to be completed with ALL options required. 
      • Add a course to 'Condition: Completion of other courses'
      • Submit / complete activities in the course
      • Complete the required course
      • Run the cron
      • Go to course completion progress block - report is okay and visible

      Breaking behaviour

      • Course Completion criteria will be locked after submission.  
      • Unlock course completion criteria
      • Change from ALL options to ANY options. 
      • Add / remove an existing tick or option
      • Save

       OR

      • Delete required course
      • Navigate to the course with Course Completion enabled
      • You will se an error: "Notice: Trying to get property 'id' of non-object in /var/www/site/completion/criteria/completion_criteria_course.php on line 138"

      When course completion options come up again it includes a completion criteria that other courses be completed with no other courses filled in - even though it was not selected by the user above. 

      If you go to course completion progress block again - gives error.

       

      Can't find data record in database table course.

       

      More information about this error

      Debug info: SELECT id,category FROM {course} WHERE id IS NULL
      [array (
      )]
      Error code: invalidrecord

      Stack trace:

      • line 1546 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
      • line 1522 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
      • line 6818 of /lib/accesslib.php: call to moodle_database->get_record()
      • line 138 of /completion/criteria/completion_criteria_course.php: call to context_course::instance()
      • line 409 of /report/completion/index.php: call to completion_criteria_course->get_title_detailed()

       

      After looking around I found some records in the database that had null modules. 

      You can identify them with

      SELECT * FROM prefix_course_completion_criteria where module is null; 

      By deleting these null records I was able to access the Course Completion reports that I was unable to access before. I also found that this was somehow linked to criteriatype 8 or criteria type 7 in the database. 

      It may be unrelated but I also found a lot of duplicated values in prefix_course_completions. I literally had hundreds of duplicated values for the same courses that was affected by the predix_course_completion_criteria. 

      I was able to reproduce the problem and it seems that it breaks not because of the null value on the criteriatype=7 records but rather because of the single criteriatype 8 record that gets added by https://github.com/moodle/moodle/blob/master/completion/criteria/completion_criteria_course.php at line 85 onwards. 

       

       

      Hope this helps someone to identify and fix this problem which seems to be have been around for a while. 

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            riaansteenberg Steenberg
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: