Duplicate entry 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXX' for key 'PRIMARY' query: INSERT INTO drupal_fb_user_app (apikey, fbu, added, session_key, session_key_expires, time_access, uid, proxied_email, time_cron) VALUES ('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', XXXXXXXXX, 1, '', 0, 1280899398, 8, '', 0) in /x/x/x/x/x/sites/all/modules/fb/fb_user.module on line 133.

The _fb_user_track function is sometimes being called multiple times. In my case when loading the ubercart checkout page, it's run 4 times.

If the UPDATE query in _fb_user_track is run these multiple times, it's likely that time() will be the same on repetitive runs and db_affected_rows will return 0.

I tried to use static and global variables to limit the function to run once but was unsuccessful.

I ended up replacing:

    if ($result && !db_affected_rows()) {

with:

    if ($result && !db_fetch_object(db_query("SELECT * FROM {fb_user_app} WHERE apikey='%s' AND fbu=%d", $fb_app->apikey, fb_facebook_user($fb)))) {

Comments

Dave Cohen’s picture

Thanks for that explanation of why db_affected_rows might return 0. This issue has been reported elsewhere and I was staring at the code, not sure how it was possible.

I'm not sure your fix is the best. The last thing I want to do is add another one (or more) database query to every page.

I'm open to other ideas on how to best handle this. In 3.x, I'm thinking of moving all the tracking into its own module (sort of like drupal's db log module) so high-performance sites can avoid it entirely.

Dave Cohen’s picture

Status: Active » Fixed

The user tracking has moved to modules/fb/contrib/fb_user_app.module. And I believe this problem is fixed, but pleas re-open issue if I am wrong.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rkarajgi’s picture

Version: 6.x-2.x-dev » 6.x-3.0-rc7

I am using the 6.x-3.0-rc7 (latest) module. It is working great - the user adding part when new FB user logs in is terrific.

I am getting the same "Duplicate Entry error" while INSERT into fb_user (uid, fbu).

I think this error happens when:
- I use FB Login with a new FB user that creates a new Drupal user
- I use Drupal user management to delete the newly created user
- I try to use FB Login with the same FB user

I believe when Drupal user management deletes the user, it perhaps does not delete the user from fb_user table.

Any ideas how I can get rid of these Duplicate entry errors?

rkarajgi’s picture

FYI:

I emptied the fb_user and fb_user_app tables (this is new project but I copied db from an earlier project) and the errors went away.