-
Notifications
You must be signed in to change notification settings - Fork 212
MailPoet sync: bug when course name is larger than MailPoet's Segment Name DB column max length #7925
Description
We're seeing Sensei's MailPoet sync job (sensei_background_job_stateful) fail in an infinite retry loop when a course title generates a segment name longer than MailPoet's wp_mailpoet_segments.name column limit.
The flow:
Sync_Job::run_batch()callsRepository::get_list_name()which generates "Sensei LMS Course: {title}"get_mailpoet_lists()returns segments keyed by the name stored in the DB (which MySQL truncated on the original INSERT)array_key_exists()fails because the full-length name doesn't match the truncated stored namecreate_list()tries to INSERT — MySQL truncates again — duplicate key violation- The DB exception closes Doctrine's EntityManager permanently for that PHP process
create_list()catchesAPIException, but the EntityManager is already closed — every subsequent MailPoet DB call in that batch fatals with "The EntityManager is closed"- Action Scheduler marks the job as failed and retries. This repeats every minute indefinitely.
We accumulated 180k+ failed actions before catching it.
Two things that would fix this on Sensei's side:
- Truncate the segment name to fit within MailPoet's column limit before both the lookup (
array_key_exists) and the insert (create_list). MailPoet is increasing their column to 191 but any limit can be exceeded with a long enough title. - Handle the Doctrine EntityManager closure gracefully. When
create_list()fails, the EntityManager is dead for the rest of the request. The sync should detect this and bail out of the batch cleanly instead of continuing to call MailPoet APIs that will all fail.
Relevant code:
includes/mailpoet/class-sync-job.php—run_batch()lines 48-61includes/mailpoet/class-main.php—create_list()lines 233-245includes/mailpoet/class-repository.php—get_list_name()line 76
We've applied a workaround on our end (increased the wp_mailpoet_segments.name column limit ) but this should likely be fixed upstream as it will still fail if the title is large enough .
Steps to Reproduce
- You need both sensei and mailpoet installed / configured on the site
- Create a new Course with a really long name (anything over 80 characters would work)
- Check the Scheduled Actions page
- You'll notice that the Failed list will start growing as this job tries to create a segment with the course name BUT the course name is larger than the segment name column size in the DB
What I Expected
I would expect the job to consider the max length of the DB column and search for a truncated value of the course name (if larger than the limit) to make sure that it indeed finds a segment for that course if one has been created.
What Happened Instead
It keeps searching for the full course name in segments and can't find it. hence it fails and keeps retrying.
PHP / WordPress / Sensei LMS version
Sensei: Woo Paid Courses extension from WooCommerce.com
Latest (tested up to PHP 8.5, WordPress 7.0, but also with PHP 8.5 and WP 6.9).
Browser / OS version
Tested in Zen (Firefox) and Chrome