diff --git a/lib.php b/lib.php index 2caad79..e679979 100644 --- a/lib.php +++ b/lib.php @@ -938,7 +938,7 @@ function coursework_get_coursework_ids_from_context_id($contextid) { $coursemodule = get_coursemodule_from_id('coursework', $context->instanceid); $courseworkmoduleid = $DB->get_field('modules', 'id', ['name' => 'coursework']); - if ($coursemodule->module == $courseworkmoduleid) { + if ($coursemodule && $coursemodule->module == $courseworkmoduleid) { $courseworkids[] = $coursemodule->instance; } break; diff --git a/tests/generator_test.php b/tests/generator_test.php index 1877f5e..b58cbe7 100644 --- a/tests/generator_test.php +++ b/tests/generator_test.php @@ -46,6 +46,10 @@ final class generator_test extends \advanced_testcase { */ public function setUp(): void { $this->resetAfterTest(true); + // If we don't do this, we end up with the same cached objects for all tests and they may have incorrect/missing properties. + \mod_coursework\models\coursework::$pool = null; + \mod_coursework\models\course_module::$pool = null; + \mod_coursework\models\module::$pool = null; } /**