[CRM-9091] Fatal error occurs when account registration matches a contact with an existing account Created: 25/Oct/11 Updated: 17/Apr/15
|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:||Future Version|
|Reporter:||Dave Schafer||Assignee:||Donald A. Lobo|
|Remaining Estimate:||Not Specified|
|Time Spent:||Not Specified|
|Original Estimate:||Not Specified|
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
[callback] => Array
 => CRM_Core_Error
 => 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 , 'email@example.com' , 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 , 'firstname.lastname@example.org' , 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 , 'email@example.com' , 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
/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
/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.