customcert - Duplicate customcert_issue records causing Scheduled task to fail

customcert - Duplicate customcert_issue records causing Scheduled task to fail

by Ray Hinton -
Number of replies: 3

I am using customcert 3.6.3 (2018120303).

I recently upgraded to Moodle 3.6.5+ (Build: 20190718) and, at the same time, I am phasing out the old certificate plugin in favor of customcert. So, I've been checking Scheduled tasks once a day, just to make sure things are running smoothly.

I noticed today that \mod_customcert\task\email_certificate_task was failing. Long story short, I found that one person appears to have duplicate certificates (userid and customcertid the same for 2 records; timecreated is also the same; code is unique). That is causing the Scheduled task to fail, and preventing me/the user from downloading the certificate.

Running it manually, I got an error message like this:

Scheduled task failed: Handles emailing certificates. (mod_customcert\task\email_certificate_task),Multiple records found, only one record expected.
Debug info:
SELECT * FROM {customcert_issues} WHERE userid = ? AND customcertid = ?
[array (
  0 => '12345',
  1 => '5',
)]


(note: userid number has been changed.)

Indeed, in customcert_issues, I see two records for that user, with the exact same timestamp. There are no other records with duplicate userid and customcertid values.

When I download the CSV from the plugin, I only see one record for the person with the matching email address. I cannot tell which "issue" record it thinks it is reporting, since it does not reference the code or issue id number. When I try to download the certificate for that person, I get the same kind of error as above.

When I hover my mouse over the delete button, it does mention an actual customcert_issues id number - the one with the higher id number.

There do not appear to be an abnormal number of grade_grades, grade_history, or quiz_attempts records for this person.

Do you think this is just some odd hiccup from my server or something? Or a bug, which I could possibly help more with identifying?

And to resolve it, do you have any suggestions? In the plugin interface, I do see there is a "delete" button. For the sake of diagnosing the problem, I am tempted to leave it alone. But, it is also causing any other new issues (for other users) to fail emailing the certificate. smile

To put it another way: I understand what is causing the Scheduled task and so on to fail (there are duplicate records). I do not understand how the duplicate records were created in the first place. I think I can solve the immediate problem (delete the bad certificate using the plugin), but I am always curious to figure out why things happen.

Anyway, thanks for this great plugin! I'll update with any other information or actions I take.

- Ray

Average of ratings: -
In reply to Ray Hinton

Re: customcert - Duplicate customcert_issue records causing Scheduled task to fail

by Ray Hinton -
Update: I used the plugin interface to delete the certificate for the person with duplicate records. I looked in the database table, and indeed, they now only had one customcert_issues record. Then I could download a certificate for them. After clearing the fail delay for the Scheduled task, it is running normally and sending out the backed up emails.

So, that resolves the immediate issue, but I am still curious as to how I ended up with duplicate customcert_issues records.
In reply to Ray Hinton

Re: customcert - Duplicate customcert_issue records causing Scheduled task to fail

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
In reply to Mark Nelson

Re: customcert - Duplicate customcert_issue records causing Scheduled task to fail

by Ray Hinton -
Thanks for taking a look, Mark! Good to know that you're familiar with this kind of thing, at least, and that it does not seem to be a frequent occurrence.