After updating the core to 7.50, new user registration randomly gives the following error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temporary://220_8.jpg' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 9186 [:db_insert_placeholder_1] => 220_8.jpg [:db_insert_placeholder_2] => temporary://220_8.jpg [:db_insert_placeholder_3] => image/jpeg [:db_insert_placeholder_4] => 51931 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1473329228 ) in drupal_write_record() (line 7378 of /srv/bindings/7a122cc082fe43ccb2d9c66bfa30ef9b/code/includes/common.inc).

The error causes the registration page to show "The website encountered an unexpected error. Please try again later".

Disabling the option Enable random default avatar image is fixing the problem.

Avatar selection is not set up to appear on the registration page.

Thanks!

Comments

davide.catani created an issue. See original summary.

robit8deb’s picture

Same here - something to do with the temporary files created when someone selects an avatar. This needs to get fixed.

Ron Collins’s picture

Assigned: Unassigned » Ron Collins

I'm going to take a shot at fixing this. If anyone has any new information about it, now's the time to bring it.

Ron Collins’s picture

I think this is not a bug in the Avatar Selection module so much as a not very robust file_managed strategy by Drupal core. It seems there are lots of other issues related to this.

I believe this problem happens when files and the file_managed table get out of sync. This could happen when moving a site between servers (prod to dev or local for instance).

For that reason, I suspect it is better for sites to have their temporary directories set to sites/default/files/temp instead of something like /tmp.

To clean up the mess, I first checked that the fids of the files which where causing errors:
select fid from file_managed where uri like 'temporary://';
Then I made sure those files (all avatars) were not being used in the avatar_selection table:
select fid from avatar_selection;
Then I went back and deleted the file references from the file_managed table:
delete from file_managed where uri like 'temporary://';

I also deleted some related files from /tmp (after I changed my temp directory to sites/default/files/temp

I'll dig deeper if this comes back but I'm not sure what else can be done without digging into core.

Ron Collins’s picture

Assigned: Ron Collins » Unassigned