Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
530 stars 197 forks source link

WordPress database error Duplicate entry for key 'PRIMARY' for query INSERT INTO `wp_term_relationships` #7623

Closed telegraphical closed 2 weeks ago

telegraphical commented 2 months ago

Steps to Reproduce

  1. Complete a Course
  2. 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

donnapep commented 1 month ago

Hello @telegraphical. We currently only support WordPress 6.3 or higher and the latest version of Sensei. Could you please try upgrading your site to WordPress 6.3+ and Sensei 4.24.1 and see if the issue persists? Thanks.

donnapep commented 2 weeks ago

I'm going to close this issue. Please let us know if it can be reproduced on a newer version of WordPress.