sensei
sensei copied to clipboard
WordPress database error Duplicate entry for key 'PRIMARY' for query INSERT INTO `wp_term_relationships`
Steps to Reproduce
- Complete a Course
- Sometimes an error occurs as seen below, which stops actions and hooks being fired for the course completion.
What I Expected
For an action to be triggered in a custom plugin that catches when a user has completed a course
What Happened Instead
Rarely, we get the following error in the error logs, but no errors on the frontend. No actions or hooks are fired.
stderr: WordPress database error Duplicate entry '36641-79626' for key 'PRIMARY' for query INSERT INTO wp_term_relationships (object_id, term_taxonomy_id) VALUES (36641, 79626) made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/plugins/sensei-lms/templates/single-course.php'), do_action('sensei_single_course_content_inside_before'), WP_Hook->do_action, WP_Hook->apply_filters, Sensei_Course->the_progress_statement, Sensei_Course->get_progress_statement, Sensei_Course::is_user_enrolled, Sensei_Course_Enrolment->is_enrolled, Sensei_Course_Enrolment->save_enrolment, wp_set_post_terms, wp_set_object_terms
In the last 6 months this has happened around 20 times, but it is being noticed. This happens on multiple installs, all PHP 8 and all WP versions > 5.2
PHP / WordPress / Sensei LMS version
PHP 8.4 WP 5.5.4 Sensei LMS 4.20.0