3 replies [Last post]
captaindan@drupal.org's picture
Offline
Joined: 09/09/2008
Juice: 28
Was this information Helpful?

BUG:
First anonymous customer who would try to checkout, will see the error:

user warning: Duplicate entry '1' for key 1 query: INSERT INTO users (name, mail, init, pass, status, uid, created) VALUES ('drupaller', 'drupaller@drupal.org', 'drupaller@drupal.org', '59647d94724bcbf0a3c0dedb83127fc6', 1, 1, 1220950180) in W:\home\ubercart.dan\www\includes\database.mysql.inc on line 172.

The good news are that the order will be registered and available for processing.Customer will also get his account details, but he won't ever log in, because the account hasn't been created!
REASON:
After a couple of hours of code researching I've figured out that the above error is caused by calling user_save function from uc_order.module at line 2293.
user_save function calls db_next_id function from user.module at line 174.
And at that moment db_next_id returns uid = 1, which is already taken for Drupal superuser!
And then no wonder that database query from user.module at line 211 causes an error.
db_next_id makes its queries to sequences database table, which doesn't contain a row users_uid before the first call. That's why it returns uid=1.
SOLUTION:
To fix this bug we need to create a row for users_uid in sequences table during the installation of uc_cart.module, for example. I'm not that clear how to do that correctly, in Drupal-like manner, so I'm asking you guys to help me with that.
Will the code below be a patch for the bug?

//somewhere in the uc_cart_install()...
$max_uid = db_result(db_query("SELECT MAX(uid) AS max_uid FROM {users}"));
if ($max_uid) {
  db_query("INSERT INTO {sequences} (name, id) VALUES ('{users}_uid', $max_uid)");
}
//somewhere in the uc_cart_uninstall()...
  db_query("DELETE FROM {sequences} WHERE name = '{users}_uid'");

Thanks a lot for your time!
I'm looking forward for your reply.
Best regards,
captaindan.

PreviewAttachmentSize
uc_cart.install.txt2.82 KB
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: First anonymous user checkout error

This sounds like a problem with the way Drupal was installed, rather than an Ubercart specific issue. If creating the superuser doesn't add the users_uid row to the sequences table, then an error should occur no matter how the second user gets created.

Can you make a new Drupal install, and see if sequences.users_uid has a value in it? Check both before and after the first user is created.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: First anonymous user checkout error

Aye, a patch for this problem ought to be in Drupal core. I haven't noticed it on any of my test sites, though.

captaindan@drupal.org's picture
Offline
Joined: 09/09/2008
Juice: 28
Re: Re: Re: First anonymous user checkout error

Yes, you're right - it's all about Drupal installation.
For my site, I used Russian Drupal Installer (RDI). It provides a localized interface and automatically creates first user "admin" shortly after installation process. But RDI doesn't populate sequences table with users_uid row.
I also tried origin Drupal files and it runs well.
I guess I gotta find another way to localize my Drupal sites and warn the Ubercart russian community about that bug in RDI.

Thank you so much for your participation!
I'll try to do the better research next time, before bothering you.