-
Bug
-
Resolution: Fixed
-
Critical
-
2.7
-
MOODLE_27_STABLE
-
MOODLE_27_STABLE
-
45248-27
-
Coding error detected, it must be fixed by a programmer: Context passed must be course context.
More information about this error
Debug info:
Error code: codingerror
Stack trace:
line 115 of /lib/classes/event/course_viewed.php: coding_exception thrown
line 252 of /lib/classes/event/base.php: call to core\event\course_viewed->validate_data()
line 308 of /course/view.php: call to core\event\base::create()
This first came to light by behat tests as illustrated by the following fail:
(::) failed steps (::)
|
|
01. Moodle exception: Coding error detected, it must be fixed by a programmer: Context passed must be course context. More information about this error
|
|
Debug info:
|
|
Error code: codingerror
|
|
Stack trace:
|
|
line 115 of /lib/classes/event/course_viewed.php: coding_exception thrown
|
line 252 of /lib/classes/event/base.php: call to core\event\course_viewed->validate_data()
|
line 289 of /course/view.php: call to core\event\base::create()
|
In step `And I press "Save changes"'. # behat_forms::press_button()
|
From scenario `Restore a backup into a new course changing the course format afterwards'. # /var/www/integration/backup/util/ui/tests/behat/restore_moodle2_courses.feature:82
|
Of feature `Restore Moodle 2 course backups'.
|
After a bit of research I find that it is in fact because of the social course format, looking at https://github.com/samhemelryk/moodle/blob/master/course/view.php#L286 before this line $context is instance of context_course.
After this line $context is instance of context_module.
Now it appears to me that the course format should not change $context (a downside to executing format code in the global scope).
However I wonder if it is also a flaw of the logging code. I would bet that social isn't the only format that does this nasty. Perhaps we need to double check the context before instantiating the event data.