Errors when ubercart creates a user

Posts: 67
Joined: 05/05/2008
Bug Finder

Hi all,

I've ran into a problem.

Everything was working fine before, but yesterday the following started happening:

When a user completes checkout through ubercart (ie, buys a product and ubercart creates a user), a bunch of errors come up:

<?php
# user warning: Duplicate entry '' for key 2 query: INSERT INTO users (uid, created) VALUES (304, 1215821978) in C:\!yuriy\www\sitename\includes\database.mysql.inc on line 172.
# user warning: Duplicate entry '0' for key 1 query: INSERT INTO trialrole (uid, trial, created) VALUES (0, 0, 1215821980) in C:\!yuriy\www\sitename\includes\database.mysql.inc on line 172.
# user warning: Duplicate entry '' for key 2 query: INSERT INTO users (uid, created) VALUES (305, 1215821980) in C:\!yuriy\www\sitename\includes\database.mysql.inc on line 172.
# user warning: Duplicate entry '0' for key 1 query: INSERT INTO trialrole (uid, trial, created) VALUES (0, 0, 1215821981) in C:\!yuriy\www\sitename\includes\database.mysql.inc on line 172.
# warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\!yuriy\www\sitename\modules\mimemail\mimemail.module on line 247.
?>

This does not happen when a user simply registers, which leads me to believe this is something within Ubercart. Now, this copy has been hacked to bits, but I didn't make any major modifications to the site yesterday (when this problem happened), and definitely didn't touch anything to do with user registration, so there is a chance that this is a bug or misconfiguration of some sort.

Now, a bit about the errors...

First and third - no idea what it is.
Second and fourth - from a custom module which has been working fine for a few months of development. Query occurs during the 'insert' case of the hook_user() function.
Fifth - no local SMTP server, so you can ignore this one.

Also, the account and order DO get created properly, user gets logged in, etc.

I doubt anyone will be able to pinpoint a solution, but maybe a general idea of where to look for the problem?

Thanks!

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Unfortunately, I'm not sure I'll be much help. Ubercart creates new users upon checkout completion for anonymous users only. When it does, it builds an array of fields and saves that as a new user using Drupal's function user_save(). So, Drupal is controlling the actual queries that get fired off with nothing fishy on the Ubercart side.

I can't really make sense of those errors you're getting, either. Puzzled

Posts: 67
Joined: 05/05/2008
Bug Finder

Thanks for the reply, Ryan.

I've been digging around for about 3 hours now, and have narrowed down the problem to Workflow NG.

I have a rule which gets invoked whenever a new subscription is registered. It acts on the customer (user), and does the following: removes 4 roles, adds 1.

Disabling this workflow rule gets rid of the errors, but also of key functionality... I'll probably submit this in the issue que for the workflow-ng module...

Posts: 924
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

I've seen that error before when I mistakenly called user_save() on a uid of 0 (anonymous user). Perhaps that's what's happening here - are you trying to remove a role from uid 0? I don't know if the new user is created yet at that point in the checkout where you're running those actions.

--

<tr>.

Posts: 67
Joined: 05/05/2008
Bug Finder

Hi TR,

that's what I'm leaning towards... I think that's what's happening.

I've been playing with the role removal and it definitely happens when I try to remove a user role. As a matter of fact, I just had an empty action on the 'New subscription has been registered' event and everything was working fine. As soon as I added the action to remove a certain role, the error popped up.

My situation is as follows:
If an anonymous user purchases a subscription, they get a new account and get set the 'paid member' user role.
If a registered user purchases a subscription, they also get the 'paid member' role, but also lose the following roles: canceled member, exit member, trial member, trial (expired) member.

So far I've just had a single workflow-ng rule handling all of the above. Maybe I need to make two separate rules for anonymous and logged in users...

Will try it out and report after lunch Smiling

Posts: 67
Joined: 05/05/2008
Bug Finder

I made different rules for logged in and logged out users - still got the same problem.

The problem also occurs when I *add* roles when the event occurs - not just on role removal...

Is there a way for me to delay the role operations until *after* the user gets created? Can't seem to figure this one out in workflow...

//edit

The event I'm assigning the rules to is 'New subscription has been registered.' Shouldn't the user be already created at this point?

//edit2

Just took a look at the uc_subscriptions table - all my tests today have been creating subscriptions with UID = 0 Sad... Great...

Isn't it just wonderful when stuff works fine on Friday evening, but by Monday morning it's practically exploding?

Posts: 4
Joined: 10/16/2008

How would one put the option to buy a role on the registration page?

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

@LoveGolf - this isn't really the thread for that question...

@kerunt - Hmmm... yes, new user accounts are being created before the "Customer completes checkout" event gets fired, but I'm curious if you're using a different event?