[CRM-9091] Fatal error occurs when account registration matches a contact with an existing account Created: 25/Oct/11  Updated: 02/Jun/16  Resolved: 19/Oct/15

Status: Closed
Project: CiviCRM
Component/s: Core CiviCRM
Affects Version/s: 3.3.6, 3.4.alpha, 3.4.beta, 3.4.0, 3.4.1, 3.4.2, 3.4.3, 3.4.4, 3.4.5, 3.4.6, 3.4.7, 4.0.0, 4.0.1, 4.0.2, 4.0.3, 4.0.4, 4.0.5, 4.0.6, 4.0.7
Fix Version/s: Unscheduled

Type: Bug Priority: Minor
Reporter: Dave Schafer Assignee: Unassigned
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Required?: None
Funding Source: Needs Funding


We have identified this issue in 3.3.5 and the current drupal demo site.

The general problem is - if when creating a drupal registration, the registration information provided matches a contact record that already has an associated drupal account, a fatal DB error occurs.
I'm guessing this is a primary key violation on contact id since none of the drupal account validations fail (email, username).

I reproduced this on the current demo site as follows

1 - find a contact with 2 email addresses
2 - register using the first email address - verify that account is linked to contact
3 - register using the second email address
4 - error occurs

Here is the error I received

Database Error Code: Duplicate entry '27-1' for key 3, 1062
Additional Details:

[callback] => Array
[0] => CRM_Core_Error
[1] => handle

[code] => -5
[message] => DB Error: already exists
[mode] => 16
[debug_info] => INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 47 , 'adamssam@indiatimes.co.pl' , 27 ) [nativecode=1062 ** Duplicate entry '27-1' for key 3]
[type] => DB_Error
[user_info] => INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 47 , 'adamssam@indiatimes.co.pl' , 27 ) [nativecode=1062 ** Duplicate entry '27-1' for key 3]
[to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALUES ( 1 , 47 , 'adamssam@indiatimes.co.pl' , 27 ) [nativecode=1062 ** Duplicate entry '27-1' for key 3]"]

Here is the backtrace
/var/www/drupal.civicrm.org/svn/civicrm34/CRM/Core/Error.php, backtrace, 159
, handle,
/var/www/drupal.civicrm.org/svn/civicrm34/packages/PEAR.php, call_user_func, 931
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB.php, PEAR_Error, 968
/var/www/drupal.civicrm.org/svn/civicrm34/packages/PEAR.php, DB_Error, 564
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB/common.php, raiseError, 1903
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB/mysql.php, raiseError, 898
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB/mysql.php, mysqlRaiseError, 327
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB/common.php, simpleQuery, 1216
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB/DataObject.php, query, 2424
/var/www/drupal.civicrm.org/svn/civicrm34/packages/DB/DataObject.php, _query, 1054
/var/www/drupal.civicrm.org/svn/civicrm34/CRM/Core/DAO.php, insert, 288
/var/www/drupal.civicrm.org/svn/civicrm34/CRM/Core/BAO/UFMatch.php, save, 194
/var/www/drupal.civicrm.org/svn/civicrm34/drupal/civicrm.module, synchronize, 541
/var/www/drupal.civicrm.org/svn/civicrm34/drupal/civicrm.module, civicrm_register_data, 402
/var/www/drupal.civicrm.org/public/modules/user/user.module, civicrm_user, 21
/var/www/drupal.civicrm.org/public/modules/user/user.module, user_module_invoke, 339
/var/www/drupal.civicrm.org/public/modules/user/user.module, user_save, 2360
/var/www/drupal.civicrm.org/public/includes/form.inc, user_register_submit, 781
/var/www/drupal.civicrm.org/public/includes/form.inc, form_execute_handlers, 421
/var/www/drupal.civicrm.org/public/includes/form.inc, drupal_process_form, 120
, drupal_get_form,
/var/www/drupal.civicrm.org/public/includes/menu.inc, call_user_func_array, 349
/var/www/drupal.civicrm.org/public/index.php, menu_execute_active_handler, 17

We are seeing this issue with clients that have contacts will multiple emails. The individual generally has a personal email and an organization related email.
They often forget they have an existing account or can't follow the password reset process. So when they try and recreate the account with the first email and it failed because it is duplicate they then go and register again using their secondary email.

It seems that there are few options for handling this

1 - change the database constraint to allow the 2 account to be linked to the contact (there is probably some downside to this but none immediately come to mind)
2 - display a message that this is a duplicate account and provide a link to request a password reset and somehow pre-pop the original email associated with the account)

The only issue I see with option 2 is that we see a lot of environments where site use is sporadic (only once or twice a year) if the original email on the account is no longer valid there is no way for the user to correct it, so creating a second account is the only solution.

I think sim

Comment by Donald A. Lobo [ 28/Oct/11 ]

Resolved this by ensuring that if there is a match (and hence a violation), we create a new contacts and match it to the user record. The organization can then do a merge via the admin screen and sort out what needs to be done

Comment by Dave Schafer [ 28/Oct/11 ]

I'm not really sure the chosen approach is really the most viable.

Our clients struggle continually with users creating duplicate contacts through various means, this is creating yet another opportunity for that to happen.

In most cases we expose a lot of contact information via profiles and it could cause a lot of duplication and or support calls if all of a sudden it appeared that a users information was gone. (most user won't realize it is a new account / contact)

I think it would be preferable to prevent the creation of the new account. The use could receive the message:

"Sorry, this account cannot be created. The email address <insert new address here> is associated with a contact that has an existing account"

Comment by Donald A. Lobo [ 28/Oct/11 ]

I did the fix at a lower level which might be called when synching contacts / login (if accounts were created before civi was installed etc). So I do think the fix makes sense where it is.

Having a formRule that checks the condition and prevents the above case from happening is potentially a good solution. I took a quick look at the code and the fix is probably a bit more involved than what i patched. We can discuss when we chat next week.

Comment by Jamie Novick [ 11/May/12 ]

Although not the same issue this is possibly linked:

On one of our implementations Civi generates a DB error when a new user signs up through drupal to make a donation or personal campaign page (possibly in other scenarios) and where the email address used is already used by 2 or more contacts in CiviCRM. The system tries to link both of the contacts to the drupal user and an error is shown when the second link is unable to be made, then forces people to return to the home screen.

Has anyone else encountered this issue?

Although its not the perfect fix but we are intending to modify our code to:

  • On create a new user
  • Check whether the email address is used by more then one contact in civicrm
  • If so, create new contact rather then try and match
  • Admin can then deduplicate manually

Any thoughts? Should this be raised as a separate bug? Apprecaite this doesnt help with the additional duplicates issue.

Comment by Eileen McNaughton [ 19/Oct/15 ]

I'm going to close this out just because it's so old I suspect it's either resolved or unimportant. Please re-open or create another if you can still reproduce

Comment by Agileware [ 02/Jun/16 ]

Suitable to re-open this one? I'll create a new issue if not.

Found this same issue in 4.6.16 through a Profile-based user creation on a Contribution Page - prevented the membership on the same page from being processed fully.

Steps to reproduce:

  1. Create a contribution and profile page. Include membership on this page.
  2. Create a contact with two emails.
  3. Register drupal account for first email.
  4. (Anonymously) attempt to submit contribution page from step 1 where the details with the second email will cause cause the deduper to match the contact from step 2.

Results in a PDOException and the membership not being processed. But the contribution has already been processed by then.


#0 {CIVICRM_BASE}/CRM/Core/Error.php(235): CRM_Core_Error::backtrace("backTrace", TRUE)
#1  [internal function](): CRM_Core_Error::handle(Object(DB_Error))
#2  {CIVICRM_BASE}/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
#3  {CIVICRM_BASE}/packages/DB.php(976): PEAR_Error->PEAR_Error("DB Error: already exists", -5, 16, (Array:2), "INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALU...")
#4  {CIVICRM_BASE}/packages/PEAR.php(564): DB_Error->DB_Error(-5, 16, (Array:2), "INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALU...")
#5  {CIVICRM_BASE}/packages/DB/common.php(1905): PEAR->raiseError(NULL, -5, NULL, NULL, "INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALU...", "DB_Error", TRUE)
#6  {CIVICRM_BASE}/packages/DB/mysql.php(895): DB_common->raiseError(-5, NULL, NULL, NULL, "1062 ** Duplicate entry '1377-1' for key 'UI_contact_domain_id'")
#7  {CIVICRM_BASE}/packages/DB/mysql.php(328): DB_mysql->mysqlRaiseError()
#8  {CIVICRM_BASE}/packages/DB/common.php(1216): DB_mysql->simpleQuery("INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALU...")
#9  {CIVICRM_BASE}/packages/DB/DataObject.php(2442): DB_common->query("INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALU...")
#10 {CIVICRM_BASE}/packages/DB/DataObject.php(1060): DB_DataObject->_query("INSERT INTO civicrm_uf_match (domain_id , uf_id , uf_name , contact_id ) VALU...")
#11 {CIVICRM_BASE}/CRM/Core/DAO.php(442): DB_DataObject->insert()
#12 {CIVICRM_BASE}/CRM/Core/BAO/UFMatch.php(57): CRM_Core_DAO->save()
#13 {CIVICRM_BASE}/CRM/Core/BAO/CMSUser.php(247): CRM_Core_BAO_UFMatch::create((Array:3))
#14 {CIVICRM_BASE}/CRM/Contribute/BAO/Contribution/Utils.php(505): CRM_Core_BAO_CMSUser::create((Array:110), "email-5")
#15 {CIVICRM_BASE}/CRM/Contribute/Form/Contribution/Confirm.php(1530): CRM_Contribute_BAO_Contribution_Utils::createCMSUser((Array:110), "1377", "email-5")
#16 {CIVICRM_BASE}/CRM/Contribute/BAO/Contribution/Utils.php(332): CRM_Contribute_Form_Contribution_Confirm::processContribution(Object(CRM_Contribute_Form_Contribution_Confirm), (Array:108), (Array:107), "1377", Object(CRM_Financial_DAO_FinancialType), FALSE, TRUE, FALSE, (Array:1))
#17 {CIVICRM_BASE}/CRM/Member/BAO/Membership.php(1349): CRM_Contribute_BAO_Contribution_Utils::processConfirm(Object(CRM_Contribute_Form_Contribution_Confirm), (Array:107), (Array:87), "1377", "2", "membership", (Array:0), FALSE, 0)
#18 {CIVICRM_BASE}/CRM/Contribute/Form/Contribution/Confirm.php(1914): CRM_Member_BAO_Membership::postProcessMembership((Array:99), "1377", Object(CRM_Contribute_Form_Contribution_Confirm), (Array:87), (Array:0), (Array:0), (Array:11), (Array:1), TRUE, NULL, FALSE, "2", (Array:0), 0)
#19 {CIVICRM_BASE}/CRM/Contribute/Form/Contribution/Confirm.php(1023): CRM_Contribute_Form_Contribution_Confirm->processMembership((Array:99), "1377", (Array:0), (Array:0), (Array:87), (Array:0), 0)
#20 {CIVICRM_BASE}/CRM/Core/Form.php(345): CRM_Contribute_Form_Contribution_Confirm->postProcess()
#21 {CIVICRM_BASE}/CRM/Contribute/Form/Contribution/Main.php(1394): CRM_Core_Form->mainProcess()
#22 {CIVICRM_BASE}/CRM/Core/Form.php(345): CRM_Contribute_Form_Contribution_Main->postProcess()
#23 {CIVICRM_BASE}/CRM/Core/QuickForm/Action/Upload.php(166): CRM_Core_Form->mainProcess()
#24 {CIVICRM_BASE}/CRM/Core/QuickForm/Action/Upload.php(133): CRM_Core_QuickForm_Action_Upload->realPerform(Object(CRM_Contribute_Form_Contribution_Main), "upload")
#25 {CIVICRM_BASE}/packages/HTML/QuickForm/Controller.php(203): CRM_Core_QuickForm_Action_Upload->perform(Object(CRM_Contribute_Form_Contribution_Main), "upload")
#26 {CIVICRM_BASE}/packages/HTML/QuickForm/Page.php(103): HTML_QuickForm_Controller->handle(Object(CRM_Contribute_Form_Contribution_Main), "upload")
#27 {CIVICRM_BASE}/CRM/Core/Controller.php(353): HTML_QuickForm_Page->handle("upload")
#28 {CIVICRM_BASE}/CRM/Core/Invoke.php(312): CRM_Core_Controller->run((Array:3), NULL)
#29 {CIVICRM_BASE}/CRM/Core/Invoke.php(86): CRM_Core_Invoke::runItem((Array:15))
#30 {CIVICRM_BASE}/CRM/Core/Invoke.php(54): CRM_Core_Invoke::_invoke((Array:3))
#31 {CIVICRM_BASE}/drupal/civicrm.module(489): CRM_Core_Invoke::invoke((Array:3))
#32 [internal function](): civicrm_invoke("contribute", "transact")
#33 {DRUPAL_DOCROOT}/includes/menu.inc(527): call_user_func_array("civicrm_invoke", (Array:2))
#34 {DRUPAL_DOCROOT}/index.php(21): menu_execute_active_handler()
#35 {main}
Generated at Fri Jun 23 19:40:05 UTC 2017 using JIRA 7.3.3#73014-sha1:d5be8da522213be2ca9ad7b043c51da6e4cc9754.