Affects Version/s: 2.0
Fix Version/s: None
civicrm_contact_add() is supposed to update contacts when supplied with a contact ID, and is supposed to handle custom data addition.
It correctly handles custom data addition as demonstrated by http://svn.civicrm.org/civicrm/branches/v2.0/test-new/SimpleTest/api-v2/ContactAddWithCustomData.php
However, it fails when trying to update custom data which already exists in the db. eg, if a contact already has custom data for a specific custom data group, civicrm_contact_add() fails with a non-recoverable error.
The db error is (example):
INSERT INTO civicrm_value_1_test_group_9 SET `name2` = 'Changed information for custom field of type alphanumeric - text', domain_id = 1, entity_id = 18376 [nativecode=1062 ** Duplicate entry '1-18376' for key 2]
A modified version of ContactAddWithCustomData.php which should work (according to the documentation/advice I've received on IRC/forum/wiki) is attached. Lines 111 - 122 have been added to the SimpleTest linked above to demonstrate the error in action.