[4.5]New notifications cause failed tasks

[4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Number of replies: 14
Picture of Particularly helpful Moodlers

Just a heads up for people who upgrade to Moodle 4.5 and have suspended users in their courses. It creates a massive amount of failed tasks.

See https://tracker.moodle.org/browse/MDL-84089 for more details.

We are coping with it right now.

Average of ratings:Useful (3)
In reply to Richard van Iwaarden

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers
I have set the priority to 'major. See https://tracker.moodle.org/browse/MDL-84089

Please vote for this tracker or reply on this topic if you experience the same problems. So far no one from Moodle has replied, but I consider this to be a pretty problematic bug.
In reply to Richard van Iwaarden

Re: [4.5]New notifications cause failed tasks

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

I had a look into this but I think there's something additional causing this problem. As far as I can see the scheduled task gets the list of users via assign->list_participants() which calls assign->show_only_active_users(), and this function – as its name suggests – should exclude users who are either suspended or have suspended enrolments.

Do you have steps to reproduce this issue on a clean Moodle site? Also, is Show only active enrolments disabled under Site administration > Grades > Report settings > Grader report? I'm not certain this could affect this issue but it's worth checking.

In reply to Leon Stringer

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers

image.png

So yes, I have this set.

Did you check it with this setting?

image%20%281%29.png

I can not check if I can reproduce it on a clean moodle. Our Moodle is very complex. Students are being enrolled and unenrolled using webservices. 

Did you also check the manual enrolment with an end date and have it set to this?

image%20%282%29.png

So what happens for us is the following:

  • every student has an individual start and end date at a course (like manual enrolment, but using web services to enrol)
  • When the enrolment date ends, the student's course enrolment will be disabled, leading to status 'suspended'.

In reply to Richard van Iwaarden

Re: [4.5]New notifications cause failed tasks

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Do you have users enrolled on the affected course with authentication method = "No login" (auth = 'nologin' in mdl_users)? I think that could cause this problem.

If so, a short-term fix for the queue_assignment_due_soon_notification_tasks_for_users task could be to add lines 2383 to 2385 to mod/assign/locallib.php:

 2380             $this->participants[$key] = $sortedfilteredusers;
 2381         }
 2382 
2383         $this->participants[$key] = array_filter($this->participants[$key], function($user) {
 2384             return $user->auth !== 'nologin';
 2385         });
 2386 
 2387         if ($idsonly) {
In reply to Leon Stringer

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers
"As far as I can see the scheduled task gets the list of users via assign->list_participants() which calls assign->show_only_active_users(), and this function – as its name suggests – should exclude users who are either suspended or have suspended enrolments."
 
Obviously this doesn't work for us somehow. Is there a better way to get the real active students for an assignment?
 
Where can I find this function assign->show_only_active_users() and does it also work with custom enrolment plugins? I'm getting curious why our suspended students are seen as active. In the course they show as suspended.
In reply to Leon Stringer

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers

I think I found one of the students that generates an error in this task. I can see it is a cohort enrolment.

image.png

Something strange though...

ONE entire cohort is enrolled in this course. Yet within this cohort, students have the status active and suspended.

That should not be possible right?

So what has happened here... any idea's?

All I can think of is this:

  • Cohort is enrolled in course
  • Via webservices an individual end date for this student has been set at this specific course

In reply to Richard van Iwaarden

Re: [4.5]New notifications cause failed tasks

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

What is External unenrol action set to under Site administration > Plugins > Enrolments > Cohort sync? I think either "Disable course enrolment" or "Disable course enrolment and remove roles" will cause an enrol_cohort participant to show as Suspended when that user is removed from the cohort.

However, as far as I can see assign->list_participants() does correctly exclude such users so I don't think these users would cause the task failure.

In reply to Leon Stringer

Re: [4.5]New notifications cause failed tasks

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

I was mistaken when I said assign->list_participants() excludes suspended users. The get_enrolled_...() functions refer to the suspended status but this refers to suspended enrolments, not suspended users.

So the queue_assignment_due_soon_notification_tasks_for_users error can be resolved by editing mod/assign/locallib.php to add lines 2353 to 2355 below (in list_participants()):

 2349                     $params = array_merge($params, $keywordsparams);
 2350                 }
 2351             }
 2352 
 2353             if ($this->show_only_active_users()) {
 2354                 $additionalfilters .= " AND u.suspended = 0";
 2355             }
 2356 
 2357             $sql = "SELECT $fields
 2358                       FROM {user} u

This may not the correct solution since it changes list_participants() to treat users suspended at site level the same as users with suspended enrolments – which makes sense to me, but I'm not a teacher or admin. (An alternative approach would be to pass a flag to list_participants() to specify whether users suspended at site level should be included).

The above change should also fix queue_all_assignment_due_digest_notification_tasks but I haven't tested this yet.

Average of ratings:Useful (1)
In reply to Leon Stringer

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers
I think it's very good to exclude both suspended users at course level AND and site level. Suspended simply means that they are no longer active in the course, so why would you inform them about upcoming events. I think you shouldn't.

In the past I have also asked for a way for teachers to filter out users that are suspended at site level. Why? Because teachers don't always know that a user is suspended at site level. And that makes teachers enrol students in a course that are not even active on a Moodle site.

If this hack also fixes this problem, I love it even more. But I don't think it does?
In reply to Richard van Iwaarden

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers
I see a second tracker has been opened for what I think is the same issue: https://tracker.moodle.org/browse/MDL-84098
Average of ratings:Useful (1)
In reply to Richard van Iwaarden

Re: [4.5]New notifications cause failed tasks

by Rogelio Zambrana -

Thank you, Richard! I think you are right!

How can you disable the notification while there is a solution?

In reply to Rogelio Zambrana

Re: [4.5]New notifications cause failed tasks

by Richard van Iwaarden -
Picture of Particularly helpful Moodlers
I think in your task manager, but I'm not sure. However, these notifications are very useful to active students imho. So my advise would be not to disable them for everyone!