Hi, community!
I found a case where an error from the logs in the email task history table was shown to the instructor. This is true for both Communication MFE and the legacy page.
-
Legacy
-
Communication MFE
Displaying this error to the instructor is not helpful, as it fails to indicate the specific error that occurred.
Steps to reproduce:
- Course Verified and Audit is created
- There are only learners in Audit track
- Go to Instructor Tab → Email
- Emails send a letter to “Learners in the Verified Certificate Track”
- Check “Email Task History” table (Show Email Task History)
In the code, I found such a fuse:
# Weird things happen if we allow empty querysets as input to emailing subtasks
# The task appears to hang at "0 out of 0 completed" and never finishes.
if total_recipients == 0:
msg = "Bulk Email Task: Empty recipient set"
log.warning(msg)
raise ValueError(msg)
The incorrect display of the error on the frontend occurs because the task was not completed due to raise ValueError
, and as a result, the condition is processed:
instructor_task.task_state in [FAILURE, REVOKED]
.
Indeed, removing this block of code would result in emails being sent according to the steps described above, causing a task to remain in the PROGRESS
state indefinitely.
You can also view this in the admin panel: <lms>/admin/instructor_task/instructortask
I also discovered that it is impossible to catch this exception since the result of the task is generated in the Celery. This result is parsed and written to the InstructorTask
model.
I haven’t figured out how to address this bug yet. One idea is to prevent the creation of an email task if the number of users is 0. However, to implement this, a preliminary request would need to be sent to the backend before creating the task, to retrieve the number of users who will receive the email. If this number is greater than 0, proceed with sending the email; otherwise, display an error similar to how it’s done when no checkboxes are selected:
If anyone has any suggestions on how to address this issue, I would greatly appreciate it.