Invalid course module ID error when saving attendance or taking quiz

Invalid course module ID error when saving attendance or taking quiz

by Bass Sears -
Number of replies: 21
In our install of Moodle we get "Invalid course module ID" error when trying to save attendance for a class.

Starting in the attendance module for a specific course:
http://classes.wrfr.com/mod/attendance/manage.php?id=724

I click on a specific session and get to this page:
http://classes.wrfr.com/mod/attendance/take.php?id=724&sessionid=11&grouptype=0
... with list of students in it.

Regardless of whether I check any students or not, I scroll to bottom and click "Save" and get Invalid course module ID error on this page:
http://classes.wrfr.com/mod/attendance/take.php

If I have changed any of the students' attendance information (for example, clicking "P") that information is saved correctly, even though the next page shows an error.

6 weeks or so ago I went through large upgrade path from 1.9.x to 3.6.1. Today I upgraded successfully to 3.6.2. I turned on debugging and here's what I got:

------------------------------------------------------------------------------------------------------------  

At top of screen I get this debugging dump:

Notice: Trying to get property of non-object in /home1/wrfrcom/public_html/moodle2/lib/grade/grade_item.php on line 2499
This page should be using theme chameleon which cannot be initialised. Nor can the site theme chameleon. Falling back to boost

    line 711 of /lib/outputlib.php: call to debugging()
    line 1553 of /lib/pagelib.php: call to theme_config::load()
    line 1892 of /lib/setuplib.php: call to moodle_page->initialise_theme_and_output()
    line 386 of /lib/setuplib.php: call to bootstrap_renderer->__call()
    line ? of unknownfile: call to default_exception_handler()


------------------------------------------------------------------------------------------------------------

    
Then the actual error dump is:
Invalid course module ID

More information about this error
Debug info: SELECT id,course FROM {course_modules} WHERE id IS NULL
[array (
)]
Error code: invalidcoursemodule
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 7052 of /lib/accesslib.php: call to moodle_database->get_record()
    line 2499 of /lib/grade/grade_item.php: call to context_module::instance()
    line 1242 of /lib/grade/grade_grade.php: call to grade_item->get_context()
    line 1054 of /lib/grade/grade_grade.php: call to grade_grade->get_context()
    line 369 of /lib/grade/grade_object.php: call to grade_grade->add_feedback_files()
    line 1025 of /lib/grade/grade_grade.php: call to grade_object->insert()
    line 647 of /lib/grade/grade_category.php: call to grade_grade->insert()
    line 567 of /lib/grade/grade_category.php: call to grade_category->aggregate_grades()
    line 743 of /lib/grade/grade_item.php: call to grade_category->generate_grades()
    line 1271 of /lib/gradelib.php: call to grade_item->regrade_final_grades()
    line 2035 of /lib/grade/grade_item.php: call to grade_regrade_final_grades()
    line 290 of /lib/gradelib.php: call to grade_item->update_raw_grade()
    line 266 of /mod/attendance/locallib.php: call to grade_update()
    line 1011 of /mod/attendance/classes/structure.php: call to attendance_update_users_grade()
    line 724 of /mod/attendance/classes/structure.php: call to mod_attendance_structure->update_users_grade()
    line 63 of /mod/attendance/take.php: call to mod_attendance_structure->take_from_form_data()
    
------------------------------------------------------------------------------------------------------------


Students also get the same error when taking a quiz. If I log in as administrator then login as a student and take a quiz, after I save the quiz and submit it (ending up on this page: http://classes.wrfr.com/mod/quiz/processattempt.php) I get the same error Invalid course module ID.


At top of screen I get this debugging dump:

Notice: Trying to get property of non-object in /home1/wrfrcom/public_html/moodle2/lib/grade/grade_item.php on line 2499
This page should be using theme chameleon which cannot be initialised. Nor can the site theme chameleon. Falling back to boost

    line 711 of /lib/outputlib.php: call to debugging()
    line 1553 of /lib/pagelib.php: call to theme_config::load()
    line 1892 of /lib/setuplib.php: call to moodle_page->initialise_theme_and_output()
    line 386 of /lib/setuplib.php: call to bootstrap_renderer->__call()
    line ? of unknownfile: call to default_exception_handler()


------------------------------------------------------------------------------------------------------------

   
Then the actual error dump is:
An error occurred while processing your responses (Invalid course module ID (SELECT id,course FROM {course_modules} WHERE id IS NULL [array egg])). Click continue to return to the page you were on and try again.

More information about this error
Debug info: SELECT id,course FROM {course_modules} WHERE id IS NULL
[array (
)]
Error code: errorprocessingresponses
Stack trace:

    line 2240 of /mod/quiz/attemptlib.php: moodle_exception thrown
    line 89 of /mod/quiz/processattempt.php: call to quiz_attempt->process_attempt()
       
------------------------------------------------------------------------------------------------------------

Seems related. Any ideas?

Thanks in advance,

Bass
Average of ratings: -
In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Heidi W -

Have you found a fixing to this problem already? 

We have the same version of moodle and the same problem. Problem comes out in one course quizzes and also in user management if we want to remove someone. Interesting is that the ID error doesn't come with every user. We upgraded from 3.4 to 3.6.2.

In reply to Heidi W

Re: Invalid course module ID error when saving attendance or taking quiz

by Bass Sears -

Heidi, wish I could help, but don't really have a solution. Our problem was intermittent on quiz taking, but was going on every time we tried to take attendance.

And then, it wasn't. Nothing explicit I did on the setup side, nothing explicit that the administrator who's actually using Moodle to run classes did, it just hasn't been happening.

I can't really see how this has anything to do with it, but are you sure your cron jobs are running properly? Other than upgrading from 3.6.? (can't remember what previous version we were on) to 3.6.2 the only other major change I made was getting the cron jobs running again (I'd moved directories when I did my big upgrade from 1.9.x to 3.6.x, hadn't updated my cron path)... maybe that's something to look into?

In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Heidi W -

We have cron jobs running but maybe I should check it today. Our debugging gives exactly same rows than yours, except the last three or four rows.  

In reply to Heidi W

Re: Invalid course module ID error when saving attendance or taking quiz

by Marijan Milovec -

Hi, can you tell please if the cron job was a problem? We still didn't fix our problem too and we can't find any solution.

And it happened again when we copy the assignment from one course to another.


Thank you

In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Marijan Milovec -

The same problem on the same version of Moodle, several quizzes have the same problem


And the error is the same as your except few last lines of error but quite similar actually.


Did you have fix this problem, start to happen this yesterday so we still didn't get to the solution of the problem.

In reply to Marijan Milovec

Re: Invalid course module ID error when saving attendance or taking quiz

by Bass Sears -
Sorry, no solution yet.

Frustratingly for us, right now we do not have ANY way of generating this error consistently, it's an irregular glitch so right now having very hard time reproducing it.

Appears to be happening in our quiz area when it does happen, not necessarily to students but when it does happen it's sounds like (I'm just the IT-ish guy here) it's happening to the course administrator when he's grading quizzes.
In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Heidi W -

Not any fixing solution here either.  

I imported a new version of the problematic course and it solved the quiz saving problem. But not the problem in user management. Error comes irregularly here too. One failed quiz saving was fixed by itself (maybe because of cron?) but nothing else. 

In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Ivica Matotek -
Picture of Testers

Hi!

We have the same problem after upgrade from 3.3 to 3.6.1. Some quizzes are working without problems, some works only for local account but not for the other forms of authentication like saml. In php_log there are same errors:

PHP Notice:  Undefined offset: 27330 in ../moodle/lib/grade/grade_item.php on line 2498

PHP Notice:  Trying to get property of non-object in ../moodle/lib/grade/grade_item.php on line 2499

Database transaction aborted automatically in ../moodle/mod/quiz/processattempt.php

Default exception handler: Debug: SELECT id,course FROM {course_modules} WHERE id IS NULL [array egg] Error code: errorprocessingresponses

* line 2240 of /mod/quiz/attemptlib.php: moodle_exception thrown

* line 89 of /mod/quiz/processattempt.php: call to quiz_attempt->process_attempt()

 


In reply to Ivica Matotek

Re: Invalid course module ID error when saving attendance or taking quiz

by Andy Hill -

Hi Guys

Is there any news on this yet, i am suffering the same with invalid course ID, just upgraded to Moodle 3.6.2+ (Build: 20190215) and every-time i try to delete a course or category or even not finish a quiz by submitting it before the end i always get invalid course ID.

Has anyone been able to fix this? Has a bug been submitted so i can track the progress?

Thanks guys

In reply to Andy Hill

Re: Invalid course module ID error when saving attendance or taking quiz

by Bass Sears -
Andy, no fix for us yet. It would be great if you submitted this as a bug report, I have NOT done that because I can't reproduce it every time (that's one of the big challenges with this one, seems most people are getting it intermittently). If you have a reproducible spot this happens that would be a great candidate for a bug report, please post here if you do submit one so we can all track it as well.

-- Bass
In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Ivica Matotek -
Picture of Testers

I have open issue on tracker: https://tracker.moodle.org/browse/MDL-64808 but no response yet.

In my experience, we receive bug during copying quizzes. Sometimes when quiz is copied using duplicate icon on the same course, and sometimes when we import from another course.


Ivica



In reply to Ivica Matotek

Re: Invalid course module ID error when saving attendance or taking quiz

by Andy Hill -

Hi Ivica

Tim has kindly linked the 2 trackers together as it seems its related, so hopefully this can be resolved..

Andy

In reply to Andy Hill

Re: Invalid course module ID error when saving attendance or taking quiz

by Heidi W -
Today this ID error came in our another moodle environment (updated to version 3.6.2 yesterday). Both moodle have one course which is updated by importing new material to the old course and deleted the old materials and quizzes. I think this is the common maker in this problem. Is it possible that the problem occurs with users who has studied the material of old version too and it is no longer available?
In reply to Heidi W

Re: Invalid course module ID error when saving attendance or taking quiz

by Ivica Matotek -
Picture of Testers

Hi!

Today we find out that using hide/show maybe is a clue for solving problem. In one course we have noticed that when coping hidden quiz, we receive error and when we try to Show we receive error, but then we tried Make available then our quiz has become visible and we can access grades and we can even use Show quiz, everything was OK. But this procedure didn't help us in other courses. I think that problem is when coping hidden items such quiz, topics or course. You can try to Show course, activity or topic, maybe this will solve the problem

Ivica

In reply to Ivica Matotek

Re: Invalid course module ID error when saving attendance or taking quiz

by Carol Weaver -

Ivica--Well, I'll be!  We have been, sporadically, getting the "Invalid course Module ID" error ever since we upgraded Moodle to 3.6.1.  I tried your work around.  I went into a course and hid the activities and then un-hid them.  I can access Grades, Quizzes, etc without getting the error.

Kudos to you.  This has caused a lot of stress for us.  This definitely is not a fix, but it helps us move on.

Carol


In reply to Carol Weaver

Re: Invalid course module ID error when saving attendance or taking quiz

by Ivica Matotek -
Picture of Testers

Hi!

Also, we have tried backup/restoring and in some course, this was also helpful, in restored course we have grades and we can access every quiz without problem.


Ivica
In reply to Carol Weaver

Re: Invalid course module ID error when saving attendance or taking quiz

by Christine Jarka -

The hiding and showing of the module worked for a quiz without errors ONLY for when I (administrator) changed my role to student.

When a student logs in and takes the quiz - even one they have not taken before - the same error occurs.

In reply to Christine Jarka

Re: Invalid course module ID error when saving attendance or taking quiz

by Ivica Matotek -
Picture of Testers

Hi!

Moodle has corrected this error. On https://tracker.moodle.org/browse/MDL-64878 you can see that in 3.6.3 version it will be fixed. First try on test server than on production.


Ivica


In reply to Ivica Matotek

Re: Invalid course module ID error when saving attendance or taking quiz

by Christine Jarka -

We found out that the error for quizzes does not occur in Firefox v 65.0.2

In reply to Bass Sears

Re: Invalid course module ID error when saving attendance or taking quiz

by Florin Stroiescu -

I installed Moodle 3.7.1+ on Centos 7.6.1810, with PHP 7.3.9, Apache 2.4.6-89, MariaDB 10.4.7.

I had a significant number of errors when data needed to be inserted into a table (filters installation, importing Aiken formatted questions, adding resources to courses, etc).

All these were sorted out when I downgraded MariaDB to 10.3.17. It seems there is an incompatibility between latest version of Moodle and latest version of MariaDB.

Good luck with the course.