Answers.Body: <p>This was a core bug reported at <a href="https://lab.civicrm.org/dev/core/-/issues/1964" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/-/issues/1964</a> and the fix is available at <a href="https://github.com/civicrm/civicrm-core/pull/18223/files" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/18223/files</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-21T23:47:36.213Z
Answers.LastActivityDate: 2020-08-21T23:47:36.213Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>I believe what is happening here is that there are two contacts (B is being merged into A), both of which have a dedupe exception set for another contact (C). So the dedupe exceptions table contain records for A-C and B-C.</p>
  <p>When the merge is processed, CiviCRM is attempting to update the B-C exception to A-C (because B is being merged into A, the former B-C exception is being replaced with an A-C exception). The A-C exception already exists, hence the error and the merge failure.</p>
  <p>Removing the A-C and B-C dedupe exceptions allows the merge of B into A to proceed.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-21T20:04:44.403Z
Answers.LastActivityDate: 2020-08-21T20:10:32.103Z
Answers.LastEditDate: 2020-08-21T20:10:32.103Z
Answers.UserDisplayName: Lars SG
Body: <p>I have a few pairs of contacts for which merging fails with an immediate 503 page. For these contacts, merging always fails, while for almost all contacts, it works as expected.</p>
  <p>A couple errors are being logged, can post the other (&quot;We can't load the requested web page. This page requires cookies to be enabled in your browser settings...&quot;) if needed, but this seems like the most relevant. 5.28.2 on Drupal.</p>
  <p>There is nothing special about these contacts, as far as I can tell. Anyone have any ideas what's happening?</p>
  <pre><code>    [error] $Fatal Error Details = Array
  (
      [callback] =&gt; Array
          (
              [0] =&gt; CRM_Core_Error
              [1] =&gt; handle
          )
  
      [code] =&gt; -5
      [message] =&gt; DB Error: already exists
      [mode] =&gt; 16
      [debug_info] =&gt; UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 34632 [nativecode=1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2']
      [type] =&gt; DB_Error
      [user_info] =&gt; UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 34632 [nativecode=1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2']
      [to_string] =&gt; [db_error: message=&quot;DB Error: already exists&quot; code=-5 mode=callback callback=CRM_Core_Error::handle prefix=&quot;&quot; info=&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 34632 [nativecode=1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2']&quot;]
  )
  
   [debug] $backTrace = #0 /var/www/html/sites/all/modules/civicrm/CRM/Core/Error.php(205): CRM_Core_Error::backtrace(&quot;backTrace&quot;, TRUE)
  #1 /var/www/html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(922): CRM_Core_Error::handle(Object(DB_Error))
  #2 /var/www/html/sites/all/modules/civicrm/packages/DB.php(997): PEAR_Error-&gt;__construct(&quot;DB Error: already exists&quot;, -5, 16, (Array:2), &quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;)
  #3 /var/www/html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(575): DB_Error-&gt;__construct(-5, 16, (Array:2), &quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;)
  #4 /var/www/html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(223): PEAR-&gt;_raiseError(Object(DB_mysqli), NULL, -5, 16, (Array:2), &quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;, &quot;DB_Error&quot;, TRUE)
  #5 /var/www/html/sites/all/modules/civicrm/packages/DB/common.php(1925): PEAR-&gt;__call(&quot;raiseError&quot;, (Array:7))
  #6 /var/www/html/sites/all/modules/civicrm/packages/DB/mysqli.php(936): DB_common-&gt;raiseError(-5, NULL, NULL, &quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;, &quot;1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2'&quot;)
  #7 /var/www/html/sites/all/modules/civicrm/packages/DB/mysqli.php(406): DB_mysqli-&gt;mysqliRaiseError()
  #8 /var/www/html/sites/all/modules/civicrm/packages/DB/common.php(1231): DB_mysqli-&gt;simpleQuery(&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;)
  #9 /var/www/html/sites/all/modules/civicrm/packages/DB/DataObject.php(2696): DB_common-&gt;query(&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;)
  #10 /var/www/html/sites/all/modules/civicrm/packages/DB/DataObject.php(1829): DB_DataObject-&gt;_query(&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;)
  #11 /var/www/html/sites/all/modules/civicrm/CRM/Core/DAO.php(439): DB_DataObject-&gt;query(&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;)
  #12 /var/www/html/sites/all/modules/civicrm/CRM/Core/DAO.php(1528): CRM_Core_DAO-&gt;query(&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;, TRUE)
  #13 /var/www/html/sites/all/modules/civicrm/CRM/Dedupe/Merger.php(588): CRM_Core_DAO::executeQuery(&quot;UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...&quot;, (Array:0), TRUE, NULL, TRUE)
  #14 /var/www/html/sites/all/modules/civicrm/CRM/Dedupe/Merger.php(1344): CRM_Dedupe_Merger::moveContactBelongings(Object(CRM_Dedupe_MergeHandler), (Array:6), (Array:0))
  #15 /var/www/html/sites/all/modules/civicrm/CRM/Contact/Form/Merge.php(308): CRM_Dedupe_Merger::moveAllBelongings(32644, 34632, (Array:27))
  #16 /var/www/html/sites/all/modules/civicrm/CRM/Core/Form.php(504): CRM_Contact_Form_Merge-&gt;postProcess()
  #17 /var/www/html/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Submit.php(58): CRM_Core_Form-&gt;mainProcess()
  #18 /var/www/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Submit-&gt;perform(Object(CRM_Contact_Form_Merge), &quot;submit&quot;)
  #19 /var/www/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller-&gt;handle(Object(CRM_Contact_Form_Merge), &quot;submit&quot;)
  #20 /var/www/html/sites/all/modules/civicrm/CRM/Core/Controller.php(347): HTML_QuickForm_Page-&gt;handle(&quot;submit&quot;)
  #21 /var/www/html/sites/all/modules/civicrm/CRM/Utils/Wrapper.php(98): CRM_Core_Controller-&gt;run()
  #22 /var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(285): CRM_Utils_Wrapper-&gt;run(&quot;CRM_Contact_Form_Merge&quot;, &quot;Merge Contact&quot;, (Array:0))
  #23 /var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(68): CRM_Core_Invoke::runItem((Array:13))
  #24 /var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:3))
  #25 /var/www/html/sites/all/modules/civicrm/drupal/civicrm.module(454): CRM_Core_Invoke::invoke((Array:3))
  #26 /var/www/html/includes/menu.inc(527): civicrm_invoke(&quot;contact&quot;, &quot;merge&quot;)
  #27 /var/www/html/index.php(21): menu_execute_active_handler()
  #28 {main}
  </code></pre>
  
Tags: <duplicate-contacts>
Title: Cannot merge certain contact pairs - 503 error
ThreadText: # Cannot merge certain contact pairs - 503 error
  
  (Asked by: username_0 on 2020-08-20)
  
  I have a few pairs of contacts for which merging fails with an immediate 503 page. For these contacts, merging always fails, while for almost all contacts, it works as expected.
  A couple errors are being logged, can post the other ("We can't load the requested web page. This page requires cookies to be enabled in your browser settings...") if needed, but this seems like the most relevant. 5.28.2 on Drupal.
  There is nothing special about these contacts, as far as I can tell. Anyone have any ideas what's happening?
      [error] $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_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 34632 [nativecode=1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2']
      [type] => DB_Error
      [user_info] => UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 34632 [nativecode=1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2']
      [to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 34632 [nativecode=1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2']"]
  )
  
   [debug] $backTrace = #0 /var/www/html/sites/all/modules/civicrm/CRM/Core/Error.php(205): CRM_Core_Error::backtrace("backTrace", TRUE)
  #1 /var/www/html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(922): CRM_Core_Error::handle(Object(DB_Error))
  #2 /var/www/html/sites/all/modules/civicrm/packages/DB.php(997): PEAR_Error->__construct("DB Error: already exists", -5, 16, (Array:2), "UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...")
  #3 /var/www/html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(575): DB_Error->__construct(-5, 16, (Array:2), "UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...")
  #4 /var/www/html/sites/all/modules/civicrm/vendor/pear/pear-core-minimal/src/PEAR.php(223): PEAR->_raiseError(Object(DB_mysqli), NULL, -5, 16, (Array:2), "UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...", "DB_Error", TRUE)
  #5 /var/www/html/sites/all/modules/civicrm/packages/DB/common.php(1925): PEAR->__call("raiseError", (Array:7))
  #6 /var/www/html/sites/all/modules/civicrm/packages/DB/mysqli.php(936): DB_common->raiseError(-5, NULL, NULL, "UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...", "1062 ** Duplicate entry '23836-32644' for key 'UI_contact_id1_contact_id2'")
  #7 /var/www/html/sites/all/modules/civicrm/packages/DB/mysqli.php(406): DB_mysqli->mysqliRaiseError()
  #8 /var/www/html/sites/all/modules/civicrm/packages/DB/common.php(1231): DB_mysqli->simpleQuery("UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...")
  #9 /var/www/html/sites/all/modules/civicrm/packages/DB/DataObject.php(2696): DB_common->query("UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...")
  #10 /var/www/html/sites/all/modules/civicrm/packages/DB/DataObject.php(1829): DB_DataObject->_query("UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...")
  #11 /var/www/html/sites/all/modules/civicrm/CRM/Core/DAO.php(439): DB_DataObject->query("UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...")
  #12 /var/www/html/sites/all/modules/civicrm/CRM/Core/DAO.php(1528): CRM_Core_DAO->query("UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...", TRUE)
  #13 /var/www/html/sites/all/modules/civicrm/CRM/Dedupe/Merger.php(588): CRM_Core_DAO::executeQuery("UPDATE civicrm_dedupe_exception SET contact_id2 = 32644 WHERE contact_id2 = 3...", (Array:0), TRUE, NULL, TRUE)
  #14 /var/www/html/sites/all/modules/civicrm/CRM/Dedupe/Merger.php(1344): CRM_Dedupe_Merger::moveContactBelongings(Object(CRM_Dedupe_MergeHandler), (Array:6), (Array:0))
  #15 /var/www/html/sites/all/modules/civicrm/CRM/Contact/Form/Merge.php(308): CRM_Dedupe_Merger::moveAllBelongings(32644, 34632, (Array:27))
  #16 /var/www/html/sites/all/modules/civicrm/CRM/Core/Form.php(504): CRM_Contact_Form_Merge->postProcess()
  #17 /var/www/html/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Submit.php(58): CRM_Core_Form->mainProcess()
  #18 /var/www/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Submit->perform(Object(CRM_Contact_Form_Merge), "submit")
  #19 /var/www/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Contact_Form_Merge), "submit")
  #20 /var/www/html/sites/all/modules/civicrm/CRM/Core/Controller.php(347): HTML_QuickForm_Page->handle("submit")
  #21 /var/www/html/sites/all/modules/civicrm/CRM/Utils/Wrapper.php(98): CRM_Core_Controller->run()
  #22 /var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(285): CRM_Utils_Wrapper->run("CRM_Contact_Form_Merge", "Merge Contact", (Array:0))
  #23 /var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(68): CRM_Core_Invoke::runItem((Array:13))
  #24 /var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke((Array:3))
  #25 /var/www/html/sites/all/modules/civicrm/drupal/civicrm.module(454): CRM_Core_Invoke::invoke((Array:3))
  #26 /var/www/html/includes/menu.inc(527): civicrm_invoke("contact", "merge")
  #27 /var/www/html/index.php(21): menu_execute_active_handler()
  #28 {main}
  
  **Tags:** duplicate-contacts
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-08-21. Score: 1
  
  This was a core bug reported at <https://lab.civicrm.org/dev/core/-/issues/1964> and the fix is available at <https://github.com/civicrm/civicrm-core/pull/18223/files>
  
  
  ---
  
  ### Answer by username_0 on 2020-08-21. Score: 0
  
  I believe what is happening here is that there are two contacts (B is being merged into A), both of which have a dedupe exception set for another contact (C). So the dedupe exceptions table contain records for A-C and B-C.
  
  When the merge is processed, CiviCRM is attempting to update the B-C exception to A-C (because B is being merged into A, the former B-C exception is being replaced with an A-C exception). The A-C exception already exists, hence the error and the merge failure.
  
  Removing the A-C and B-C dedupe exceptions allows the merge of B into A to proceed.
  
  
  ---
  
  