0

I have a view that lists all the user accounts on my site. With VBO, I have a rules component, Resave user account (action set, action: save entity (user), no force saving immediately).

Recently, when I attempt to re-save all user accounts, I got an error on id=4037:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /en/batch?id=4037&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1375690632 ) in drupal_write_record() (line 7153 of /Volumes/Bullfrog/om/includes/common.inc).

And when I attempted to save all accounts again, the error occurred on id=4039:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /en/batch?id=4039&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1375691655 ) in drupal_write_record() (line 7153 of /Volumes/Bullfrog/om/includes/common.inc).

So, if I simply continue to re-save again and again, eventually all the accounts will get re-saved, but to execute this bulk operation takes about 20 minutes each time, so I will waste several hours this way. How can I analyze what is the cause of this error?

4 Answers 4

2
+50

Duplicate entry '' for key 'uri' actually says a little more than AlexK realizes, it says both that there's a file without a uri, hence the '', and that you have more than one of these, hence the Duplicate entry.

I'm guessing there's a filefield on your users, and some of these have lost part of their data for reasons I don't understand. (The same thing happened to me once during a faulty export-from-one-site-and-import-to-another).

Why the process can be "forced" by repetition I don't understand, but close inspection of the user entity and any fields that could have a 'uri' key, both through devel and the raw data in the DB, should reveal what the source of the problem is.

1

The database error you are getting there is due to Drupal trying to insert a managed file into the database which already exists. The error Duplicate entry '' for key 'uri' tells us that Drupal is trying to create a file using a URI which already exists in the database.

IMO what I think is happening is that the VBO is re-saving each user account correctly, but is trying to create a new file instance for attached files, instead of updating each attached file correctly.

I'm not sure how you would fix this specifically, but it seems to me this is a problem with the way VBO handles resaving user account. Wish I could be of more help.

2
  • 1
    Ok, thanks for this information. I should note that it is not all accounts though; it saves about 800 accounts without a problem, and then suddenly runs into maybe 5 accounts that break the bulk operation, and then saves 300 more, and then runs into another group of accounts that break the operation. Aug 5, 2013 at 10:14
  • yeah unfortunately I'm not well versed in the inner workings of VBO so I can't really help narrow down the problem in that regard. Maybe having a look at the structure of the "file_managed" table within the DB can give you a better understanding of whats going on. Aug 5, 2013 at 12:03
0

Re-load the user using user_load() before passing it to user_save(), this will ensure that fields are correctly populated, and prevent this kind of error (here uri attributes are empty) from happening

0

This turned out to be a bizarre core bug in which image files stored in user profile fields behave oddly that was getting triggered by Rules under some weird conditions.

Your Answer

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

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