fix: resolved race condition for get certificate button#2409
Conversation
|
Could you go through contribution guidelines? We want to ideally use direct sql as little as possible. Could you check out alternatives such as For the duplicates: the real fix is a DB-level unique constraint on We'll also need a data patch here, the unique constraint won't apply on sites that already have duplicate certificates. Since that one deletes data, I'm happy to add it as a co author once your part is in. Also could you resolve the conflicts (with develop branch) and add a simple test (insert a certificate, attempt a second for the same member+course, assert it's rejected / count stays 1)? Let me know if you need any help with it. Thanks for the contribution. |
Add server-side locking (SELECT ... FOR UPDATE) in create_certificate to serialize concurrent requests for the same user+course, preventing duplicate certificates from being created when the "Get Certificate" button is clicked rapidly
Add a composite unique index on (member, course) via on_doctype_update as a database-level safety net, with a DuplicateEntryError handler that gracefully returns the existing certificate.
Add a frontend loading guard and disable the "Get Certificate" button while a request is in flight to prevent unnecessary duplicate submissions.
FIXES #2408