Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-1986

Update of Contact Locations Fail with Duplicate Key Fatal Error When Location Types are Swapped


    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 1.7
    • Fix Version/s: 1.8
    • Component/s: None
    • Labels:


      When there are two locations for a contact, if we switch the location type of the first (primary) location to be the location type of the second location (and switch the second location type to some other location) - we get a fatal Duplicate Key error (example error below). This is due to the fact that we are trying to update the primary location's type first, but can't save it since it "duplicates" the key2 combination of the second location - whicch we haven't updated yet.

      Steps to recreate:

      • New Individual - first and last name and..
      • Home = primary location, only need to enter an email address
      • Billing = additional location, enter another email address
      • Save
      • Edit the same individual and..
      • change primary location type from Home to Billing
      • change additional location type from Billing to Other
      • Save
        (you'll get duplicate key error)

      ---- sample error output ----
      UPDATE civicrm_location SET entity_table = 'civicrm_contact' , entity_id = 109 , location_type_id = 1 , is_primary = 1 , name = '' WHERE ( civicrm_location.id = 103 )
      [nativecode=1062 ** Duplicate entry 'civicrm_contact-109-1' for key 2]

      NOTE: Not sure what the fix is for this. The formRule is correctly preventing the user from entering the same location type for two different locations - but that doesn't help w/ this case - since the location type ARE different. It's just that one of them matches what's in the DB for the other one. Check w/ lobo for ideas on the right way to fix this if necessary.




            • Assignee:
              shailesh Shailesh Lende
              dgg David Greenberg
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: