3

So, I can't delete or update contributions from CiviCRM 5.13 or 5.15, either through the UI or the API (v3).

This is the backtrace:

{

"error_code": "already exists",
"sql": "DELETE FROM civicrm_activity WHERE source_record_id IN (78772) AND activity_type_id IN ( 6 ) [nativecode=1062 ** Duplicate entry '78823' for key 'id']",
"trace": "#0 /var/www/html/dc/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(922): CRM_Core_Error::exceptionHandler(Object(DB_Error))\n#1 /var/www/html/dc/sites/all/modules/civicrm/packages/DB.php(985): PEAR_Error->__construct('DB Error: alrea...', -5, 16, Array, 'DELETE FROM civ...')\n#2 /var/www/html/dc/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(575): DB_Error->__construct(-5, 16, Array, 'DELETE FROM civ...')\n#3 /var/www/html/dc/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(223): PEAR->_raiseError(Object(DB_mysqli), NULL, -5, 16, Array, 'DELETE FROM civ...', 'DB_Error', true)\n#4 /var/www/html/dc/sites/all/modules/civicrm/packages/DB/common.php(1907): PEAR->__call('raiseError', Array)\n#5 /var/www/html/dc/sites/all/modules/civicrm/packages/DB/mysqli.php(933): DB_common->raiseError(-5, NULL, NULL, 'DELETE FROM civ...', '1062 ** Duplica...')\n#6 /var/www/html/dc/sites/all/modules/civicrm/packages/DB/mysqli.php(403): DB_mysqli->mysqliRaiseError()\n#7 /var/www/html/dc/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysqli->simpleQuery('DELETE FROM civ...')\n#8 /var/www/html/dc/sites/all/modules/civicrm/packages/DB/DataObject.php(2415): DB_common->query('DELETE FROM civ...')\n#9 /var/www/html/dc/sites/all/modules/civicrm/packages/DB/DataObject.php(1607): DB_DataObject->_query('DELETE FROM civ...')\n#10 /var/www/html/dc/sites/all/modules/civicrm/CRM/Core/DAO.php(439): DB_DataObject->query('DELETE FROM civ...')\n#11 /var/www/html/dc/sites/all/modules/civicrm/CRM/Core/DAO.php(1414): CRM_Core_DAO->query('DELETE FROM civ...', true)\n#12 /var/www/html/dc/sites/all/modules/civicrm/CRM/Activity/BAO/Activity.php(186): CRM_Core_DAO::executeQuery('DELETE FROM civ...')\n#13 /var/www/html/dc/sites/all/modules/civicrm/CRM/Contribute/BAO/Contribution.php(1322): CRM_Activity_BAO_Activity::deleteActivity(Array)\n#14 /var/www/html/dc/sites/all/modules/civicrm/api/v3/Contribution.php(234): CRM_Contribute_BAO_Contribution::deleteContribution(78772)\n#15 /var/www/html/dc/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(101): civicrm_api3_contribution_delete(Array)\n#16 /var/www/html/dc/sites/all/modules/civicrm/Civi/API/Kernel.php(168): Civi\\API\\Provider\\MagicFunctionProvider->invoke(Array)\n#17 /var/www/html/dc/sites/all/modules/civicrm/Civi/API/Kernel.php(99): Civi\\API\\Kernel->runRequest(Array)\n#18 /var/www/html/dc/sites/all/modules/civicrm/api/api.php(23): Civi\\API\\Kernel->runSafe('Contribution', 'delete', Array, NULL)\n#19 /var/www/html/dc/sites/all/modules/civicrm/CRM/Utils/REST.php(316): civicrm_api('Contribution', 'delete', Array)\n#20 /var/www/html/dc/sites/all/modules/civicrm/CRM/Utils/REST.php(566): CRM_Utils_REST::process(Array, Array)\n#21 /var/www/html/dc/sites/all/modules/civicrm/CRM/Core/Invoke.php(277): CRM_Utils_REST::ajax()\n#22 /var/www/html/dc/sites/all/modules/civicrm/CRM/Core/Invoke.php(85): CRM_Core_Invoke::runItem(Array)\n#23 /var/www/html/dc/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke(Array)\n#24 /var/www/html/dc/sites/all/modules/civicrm/drupal/civicrm.module(444): CRM_Core_Invoke::invoke(Array)\n#25 /var/www/html/dc/includes/menu.inc(527): civicrm_invoke('ajax', 'rest')\n#26 /var/www/html/dc/index.php(21): menu_execute_active_handler()\n#27 {main}",
"is_error": 1,
"error_message": "DB Error: already exists",
"debug_information": "DELETE FROM civicrm_activity WHERE source_record_id IN (78772) AND activity_type_id IN ( 6 ) [nativecode=1062 ** Duplicate entry '78823' for key 'id']"

}

Running the same SQL query mentioned in the backtrace in phpMyAdmin returns a single record (not sure why it's returning a Duplicate entry error in the backtrace).

I've got a backup of the same system running on version 5.11, separately but on the same server, which is completely fine - no issues at all. Tried turning off various extensions but to no avail. Fairly sure that it's to do with the server configuration, but really struggling to pin down where the issue lies.

Any advice would be very welcome. Thanks.

2
  • Do you have logging switched on? Jul 15, 2019 at 8:22
  • I do. The log entries related to the error look largely the same as the backtrace; it seems to be some issue with CiviActivity:{#2 /var/www/html/dc/sites/all/modules/civicrm/packages/DB.php(985): PEAR_Error->__construct("DB Error: already exists", -5, 16, (Array:2), "DELETE FROM civicrm_activity WHERE source_record_id IN (78772) AND activity_t...")}
    – Rich Smith
    Jul 15, 2019 at 10:20

1 Answer 1

4

Is this your production or test environment?

You could try to switch off logging, save and remove the logging tables, try to delete your contribution and see if it now works. At the end switch logging back on.....

Not sure if this is the root but potentially worth a try. (The already exists might be pointing at an entry in the log table?)

4
  • You, sir, deserve much beer. I turned logging off and contributions can now be updated and deleted. Is this an issue with the Civi core?
    – Rich Smith
    Jul 15, 2019 at 11:04
  • I do not know, I have not seen this one before :-) Have seen cases of custom fields being added programmatically which are then not in the log tables and then throw up errors. Glad it worked, you could have been searching for hours.... Jul 15, 2019 at 12:17
  • @RichSmith It looks like a data issue - you're deleting an activity that the logs believe was already deleted. Is it possible you restored a database from backup, but not the corresponding log file? That could cause this. Jul 16, 2019 at 15:25
  • Hi @jon-g-megaphone-tech. I've not restored the main database at all - not sure how the main database tables and the logging tables could have got out of sync. Interestingly, today I came across a similar issue on a completely different instance of CiviCRM - different server and a different version of Civi. This time, contribution batch entries couldn't be processed because of the logging table failing with the error "1034 ** Incorrect key file for table 'log_civicrm_contact'; try to repair it". Turning logging off allowed the batch entries to be processed.
    – Rich Smith
    Jul 26, 2019 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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