0

I get the following fatal error when trying to send an email (under 50 addresses) to a list of participants for one specific event. I can successfully email a participant list from another event.

I'm using CiviCRM 5.36.1 with Drupal 6 (Pressflow 6.56).

I'd really appreciate any ideas how to fix this.

$Fatal Error Details = Array ( [callback] => Array ( [0] => CRM_Core_Error [1] => exceptionHandler ) [code] => -3 [message] => DB Error: constraint violation [mode] => 16 [debug_info] => INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) VALUES ( 8527 , 45914 , 'b22a018b6ac6959f' ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`purcosacoza`.`civicrm_mailing_event_queue`, CONSTRAINT `FK_civicrm_mailing_event_queue_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)] [type] => DB_Error [user_info] => INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) VALUES ( 8527 , 45914 , 'b22a018b6ac6959f' ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`purcosacoza`.`civicrm_mailing_event_queue`, CONSTRAINT `FK_civicrm_mailing_event_queue_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)] [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::exceptionHandler prefix="" info="INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) VALUES ( 8527 , 45914 , 'b22a018b6ac6959f' ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`purcosacoza`.`civicrm_mailing_event_queue`, CONSTRAINT `FK_civicrm_mailing_event_queue_contact_id```


BACKTRACE

```Message  $backTrace = #0 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/Error.php(942): CRM_Core_Error::backtrace("backTrace", TRUE) #1 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(922): CRM_Core_Error::exceptionHandler(Object(DB_Error)) #2 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/db/DB.php(998): PEAR_Error->__construct("DB Error: constraint violation", -3, 16, (Array:2), "INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...") #3 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(575): DB_Error->__construct(-3, 16, (Array:2), "INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...") #4 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(223): PEAR->_raiseError(Object(DB_mysqli), NULL, -3, 16, (Array:2), "INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...", "DB_Error", TRUE) #5 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/db/DB/common.php(1928): PEAR->__call("raiseError", (Array:7)) #6 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/db/DB/mysqli.php(936): DB_common->raiseError(-3, NULL, NULL, "INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...", "1452 ** Cannot add or update a child row: a foreign key constraint fails (`pu...") #7 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/db/DB/mysqli.php(406): DB_mysqli->mysqliRaiseError() #8 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/pear/db/DB/common.php(1234): DB_mysqli->simpleQuery("INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...") #9 [...]/static/import/public_html/sites/all/modules/civicrm/packages/DB/DataObject.php(2696): DB_common->query("INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...") #10 [...]/static/import/public_html/sites/all/modules/civicrm/packages/DB/DataObject.php(1245): DB_DataObject->_query("INSERT INTO `civicrm_mailing_event_queue` (`job_id` , `email_id` , `hash` ) V...") #11 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/DAO.php(639): DB_DataObject->insert() #12 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Mailing/Event/BAO/Queue.php(41): CRM_Core_DAO->save() #13 [...]/static/files/purcosa.co.za.files/civicrm/ext/com.pesc.sparkpost/sparkpost.php(280): CRM_Mailing_Event_BAO_Queue::create((Array:3)) #14 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Utils/Hook.php(275): sparkpost_civicrm_alterMailParams((Array:9), "singleEmail") #15 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Utils/Hook/DrupalBase.php(74): CRM_Utils_Hook->runHooks((Array:165), "civicrm_alterMailParams", 2, (Array:9), "singleEmail", NULL, NULL, NULL, NULL) #16 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/Core/CiviEventDispatcher.php(172): CRM_Utils_Hook_DrupalBase->invokeViaUF(2, (Array:9), "singleEmail", NULL, NULL, NULL, NULL, "civicrm_alterMailParams") #17 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php(214): Civi\Core\CiviEventDispatcher::delegateToUF(Object(Civi\Core\Event\GenericHookEvent), "hook_civicrm_alterMailParams", Object(Civi\Core\CiviEventDispatcher)) #18 [...]/static/import/public_html/sites/all/modules/civicrm/vendor/symfony/event-dispatcher/EventDispatcher.php(44): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch((Array:1), "hook_civicrm_alterMailParams", Object(Civi\Core\Event\GenericHookEvent)) #19 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/Core/CiviEventDispatcher.php(129): Symfony\Component\EventDispatcher\EventDispatcher->dispatch("hook_civicrm_alterMailParams", Object(Civi\Core\Event\GenericHookEvent)) #20 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Utils/Hook.php(167): Civi\Core\CiviEventDispatcher->dispatch("hook_civicrm_alterMailParams", Object(Civi\Core\Event\GenericHookEvent)) #21 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Utils/Hook.php(1218): CRM_Utils_Hook->invoke((Array:2), (Array:9), "singleEmail", NULL, NULL, NULL, NULL, "civicrm_alterMailParams") #22 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Utils/Mail.php(179): CRM_Utils_Hook::alterMailParams((Array:9), "singleEmail") #23 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/BAO/ActionSchedule.php(639): CRM_Utils_Mail::send((Array:9)) #24 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/BAO/ActionSchedule.php(298): CRM_Core_BAO_ActionSchedule::sendReminderEmail(Object(Civi\Token\TokenRow), Object(CRM_Core_DAO_ActionSchedule), "50360") #25 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/BAO/ActionSchedule.php(372): CRM_Core_BAO_ActionSchedule::sendMailings(3, "20210505200124") #26 [...]/static/import/public_html/sites/all/modules/civicrm/api/v3/Job.php(207): CRM_Core_BAO_ActionSchedule::processQueue("20210505200124", (Array:2)) #27 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_job_send_reminder((Array:2)) #28 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/API/Kernel.php(149): Civi\API\Provider\MagicFunctionProvider->invoke((Array:8)) #29 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/API/Kernel.php(81): Civi\API\Kernel->runRequest((Array:8)) #30 [...]/static/import/public_html/sites/all/modules/civicrm/api/api.php(22): Civi\API\Kernel->runSafe("Job", "send_reminder", (Array:1)) #31 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/JobManager.php(134): civicrm_api("Job", "send_reminder", (Array:1)) #32 [...]/static/import/public_html/sites/all/modules/civicrm/CRM/Core/JobManager.php(66): CRM_Core_JobManager->executeJob(Object(CRM_Core_ScheduledJob)) #33 [...]/static/import/public_html/sites/all/modules/civicrm/api/v3/Job.php(118): CRM_Core_JobManager->execute(FALSE) #34 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_job_execute((Array:2)) #35 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/API/Kernel.php(149): Civi\API\Provider\MagicFunctionProvider->invoke((Array:8)) #36 [...]/static/import/public_html/sites/all/modules/civicrm/Civi/API/Kernel.php(81): Civi\API\Kernel->runRequest((Array:8)) #37 [...]/static/import/public_html/sites/all/modules/civicrm/api/api.php(22): Civi\API\Kernel->runSafe("Job", "execute", (Array:2)) #38 [...]/static/import/public_html/sites/all/modules/civicrm/drupal/drush/civicrm.drush.inc(1361): civicrm_api("Job", "execute", (Array:2)) #39 [...]/tools/drush/includes/command.inc(422): drush_civicrm_api("Job.execute", "auth=0") #40 [...]/tools/drush/includes/command.inc(231): _drush_invoke_hooks((Array:37), (Array:2)) #41 [...]/tools/drush/includes/command.inc(199): drush_command("Job.execute", "auth=0") #42 [...]/tools/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch((Array:37)) #43 [...]/tools/drush/includes/preflight.inc(67): Drush\Boot\BaseBoot->bootstrap_and_dispatch() #44 [...]/tools/drush/drush.php(12): drush_main() #45 {main}
2
  • any chance you have a munted email address for a participant? more like what Demerit is suggesting, but since you are saying 'works for A but not B' then perhaps something wrong with an address in Group B – petednz - fuzion May 6 at 2:29
  • Good idea on the email addresses - yesterday I had a look through the list and they looked OK, but its a small list of 21 contacts so a delete/replace of each address will determine if that's the prob. – Davy Ivins May 6 at 6:25
2

I eventually found the error for this problem, which was triggering an error for CiviEvent registrations and event reminders. Guidance from @Demerit and @petednz should have led me to it sooner.

The problem was caused by an email address with a 9-letter top level domain, and regex in sparkpost.php which assumes that top level domains are between 2 and 4 characters but see https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Brand_top-level_domains .

I changed the regex from 2,4 to 2,24 and the problem is resolved.

2
  • good catch Davy – petednz - fuzion Jun 22 at 21:19
  • ....and just found that the problem is not fully resolved. While registrations are now working the event reminders are triggering a 'DB Error: constraint violation'. Clearly some more digging needed :-( – Davy Ivins Jun 23 at 17:41
0

What version of that sparkpost extension do you have? It looks pretty old. It's not inserting a contact_id when it needs to. Maybe need to update to latest master version from github manually.

1
  • It has the latest version - and the site pumps out thousands of emails all the time without any overt problems. But I'll try your idea to instal the gihub master and see if that helps. – Davy Ivins May 6 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.