Regression - fatal error when merging contacts (when both in the same smart group / mailing)
This PR https://github.com/civicrm/civicrm-core/pull/17072 has introduced a fatal error when merging contacts that are both in the same smart group.
This situation can be engineered on dmaster to demonstrate the issue.
The error displayed is:
Fatal error: Uncaught CRM_Core_Exception: [0: Transaction integrity error: Expected to find active frame thrown in .../civicrm/Civi/Core/Transaction/Manager.php on line 93
The root cause is something like:
$Fatal Error Details = Array ( [callback] => Array ( [0] => CRM_Core_Error [1] => handle ) [code] => -5 [message] => DB Error: already exists [mode] => 16 [debug_info] => UPDATE civicrm_group_contact_cache SET contact_id = 159732 WHERE contact_id = 173002 [nativecode=1062 ** Duplicate entry '159732-212' for key 'UI_contact_group'] [type] => DB_Error [user_info] => UPDATE civicrm_group_contact_cache SET contact_id = 159732 WHERE contact_id = 173002 [nativecode=1062 ** Duplicate entry '159732-212' for key 'UI_contact_group'] [to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="UPDATE civicrm_group_contact_cache SET contact_id = 159732 WHERE contact_id = 173002 [nativecode=1062 ** Duplicate entry '159732-212' for key 'UI_contact_group']"] )
It throws a duplicate key issue because it can't update the contact ID so they are in the civicrm_group_contact_cache table associated with the same group twice.
We need to:
- ensure that group_contact_cache is treated as a table that needs to be handled with
UPDATE IGNORE
. - ideally, create a test that checks for merging two contacts that are members of the same smart group.