I was recently tasked with debugging some faulty magento reset password email code. I have, I think, found the culprit of the faulty behavior but I am really confused as to how to resolve it. Here is my log:

2015-04-23T15:38:02+00:00 DEBUG (7): site id is: 1
2015-04-23T15:38:02+00:00 DEBUG (7): loaded customer by email
2015-04-23T15:38:02+00:00 ERR (3): Recoverable Error: Object of class Mage_Customer_Model_Customer could not be converted to string  in /var/www/magento/apijson/customer/forgotPassword.php on line 30
2015-04-23T15:38:02+00:00 DEBUG (7): the customer is:
2015-04-23T15:38:02+00:00 DEBUG (7): new reset password link token generated
2015-04-23T15:38:02+00:00 DEBUG (7): resetToken is: 44bbce19e297c088c2bca9f97a21d020
2015-04-23T15:38:02+00:00 DEBUG (7): SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entity_id' cannot be null, query was: INSERT INTO `customer_entity_varchar` (`entity_type_id`,`entity_id`,`attribute_id`,`value`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UP DATE `value` = VALUES(`value`)

Here is the reset email password code:

  5 $customer = Mage::getModel("customer/customer");
  6 Mage::log("site id is: ".Mage::app()->getWebsite()->getId());
  7 $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
 26 if ($email) {
 27     try {
 28         $customer->loadByEmail($email);
 29         Mage::log("loaded customer by email");
 30         Mage::log("the customer is: ".$customer);
 31         $newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();                                                                                                                                                                          
 32         Mage::log("new reset password link token generated");
 33         Mage::log("resetToken is: ".$newResetPasswordLinkToken);
 34         $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
 35         Mage::log("rest password link token changed");
 36         $customer->sendPasswordResetConfirmationEmail();
 37         Mage::log("password reset confirmation email sent");                                                                                                                                                                                                              
 38     } catch(Exception $e) {
 39         Mage::log($e->getMessage());                                                                                                                                                                                                                                      
 40     }

From the log I know the code fails when it gets to the changeResetPasswordLinkToken function. However I don't understand why. I've looked online and googled a lot for the last couple of days but it seems I have stumbled onto a very unique issue. I did find this post that had an answer to my issue but unfortunately it did not work for me.

So my question for anyone who views this post is. Do you know what's causing the issue, and why changeResetPasswordLinkToken is failing? If there is a question similar to this one that you think will be of use please provide link since anything helps at this point. Thanks everyone.

3 Answers 3


I think what is happening here is the load of the customer is failing.

I would check that this customer email address is really attached to a customer and also update you log for customer to something like:

Mage::log("the customer is: ".$customer->getId());

This will show you quickly if the load fails. If the load does fail then of course setting the password token will not work.

  • This is actually what happened. I did the exact same log and realized I was using an unregistered email. Apr 24, 2015 at 19:42
  • @engineerKev glad you got it sorted in the end Apr 27, 2015 at 6:50
  • This is a rather strange error. I had previously loaded the customer record, but for some reason, after an order exception, the customer record gets nullified somewhere. Loading the customer again fixes the issue.
    – micwallace
    Aug 9, 2016 at 4:49

To help you resolve this problem I need more details.

The method $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken); calls same method from resource model. In resource model we see two rows, which most probably cause an issue:

 $this->saveAttribute($customer, 'rp_token');
 $this->saveAttribute($customer, 'rp_token_created_at');

The most probably issue is in the first row. I tried to look at customer_entity_varchar and find any values of attribute rp_token. But there were no any values with such attribute_id (attribute_id I got from eav_attribute).

Most probably Magento tries to change unexisted attribute value. To determine the issue try to put Mage::log() everywhere, as you did it before. And show us result.


Try this code:

$customer = Mage::getModel('customer/customer');

if ($customer->getId()) {
    $customerId = $customer->getId();
    $customer = Mage::getModel('customer/customer')->load($customerId);
    // generate a new password
    $newPassword = $customer->generatePassword();
} else {
    // do something here for existing customers

try {

    // save successful, send new password
    // uncomment this to send the email to the customer
    // $customer->sendPasswordReminderEmail();
} catch (Exception $e) {
    echo $e->getMessage();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.