Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Trying to call user_save() won't work on my installation. Guessing why.
$account = user_load( 10 );
$edit = array( 'mail' => "exampla@example.com" );
This will cause this error:
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] => 1302092562 ) in drupal_write_record() (line 6776 of /var/www/citius/includes/common.inc).
Any clues on how can I debug this? Thank you.
Comments
Comment #1
jorge.suarez CreditAttribution: jorge.suarez commentedSorry, that code is wrong. I forgot the user_save() call.
Comment #2
jorge.suarez CreditAttribution: jorge.suarez commentedAs I suspected, this has something to do with profile fields. After receiving this error, all the profile fields of type Image are gone forever.
I'm reproducing now this error. Please take a look at this demo: http://www.panicoenelnucleo.com/drupaltest/drupal-7.0/
- Clean 7.0 install standard.
- Enabled PHP Filter.
- Disabled user picture. Added image profile field.
- Created static page http://www.panicoenelnucleo.com/drupaltest/drupal-7.0/node/1
- The content of this page:
So, to reproduce this bug:
- Login as testuser1, password testpassword. You can also login as testuser2, testuser3 and testuser4.
- Visit http://www.panicoenelnucleo.com/drupaltest/drupal-7.0/node/1 (notice that e-mail is changed, no error is thrown)
- Add a picture in your profile.
- Visit again http://www.panicoenelnucleo.com/drupaltest/drupal-7.0/node/1
- Everything seems to be OK. Reload. Then you get these warnings:
- Reload again. Then you get the warnings again, then the fatal error:
Comment #3
jorge.suarez CreditAttribution: jorge.suarez commentedChanged title
Comment #4
jorge.suarez CreditAttribution: jorge.suarez commentedContinued testing with this demo using testuser4 and vardumped some values. Definitely, user_save() is messing up with the Image fields. Can someone else more experienced test this?
Comment #5
neutecake CreditAttribution: neutecake commentedSame problem.
After calling the user_save my filefield data is been deleted.
Comment #6
neutecake CreditAttribution: neutecake commentedI've found a solution:
Comment #7
jorge.suarez CreditAttribution: jorge.suarez commentedCan you explain your workaround for this problem? What's the issue exactly? Maybe we can fix this on Drupal Core instead of workaround the problem.
Thank you,
Comment #8
neutecake CreditAttribution: neutecake commentedI think it isn't a bug.
The user_save function updates all fields from the user, if the field isn't in the arrah of the second argument ($edit) the field wil be emptied.
Comment #9
jorge.suarez CreditAttribution: jorge.suarez commentedBut user_load() should retrieve all the data. Why not retrieve file/image fields only?. Also, Drupal shouldn't throw a PDOException like that, so this is definitely a bug to me. Maybe I don't understand something.
Comment #10
kenorb CreditAttribution: kenorb commentedSomething similar: #1163740: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed}
Comment #11
windmaomao CreditAttribution: windmaomao commentedI have the similar issue, try to empty the field before user_save, still not working.
Comment #12
kenorb CreditAttribution: kenorb commented