When plupload is enabled, and something goes wrong during file copying/uploading (e.g. corrupted or large images), media attempts to proceed anyway with the half-baked file, and will put a new record in the {file_managed} table with no URI. Since this outcome is not handled, no errors are thrown, except for a watchdog log entry, that the user may not notice:

File temporary://p19fc21br5bkrjg51nrjm8lobr4.tmp (/Applications/MAMP/tmp/php/p19fc21br5bkrjg51nrjm8lobr4.tmp) could not be copied because it does not exist.

Later, if another failure occurs, we will get a PDOException:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp, type) 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, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => application/octet-stream [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1425260317 [:db_insert_placeholder_7] => default ) in drupal_write_record() (line 7239 of /Users/attila/dev/drupal-7/includes/common.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

attila.fekete’s picture

Wrote a patch to avoid inserting such records in the db.

attila.fekete’s picture

Status: Active » Needs review
DamienMcKenna’s picture

Out of interest, are you running the site on a web cluster, i.e. with multiple web servers running the same site? If so, you might be running into a problem with the file submissions being split across the multiple servers, so the server that gets the final HTTP request only has some of the files. This is common on e.g. Acquia hosting.

TheAllverse’s picture

Please help. I get a similar message whenever I try and update my theme settings by changing the shortcut icon

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

and

'temporary://example-logo.png' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp, origname, type) 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, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => example-logo.png [:db_insert_placeholder_2] => temporary://example-logo.png [:db_insert_placeholder_3] => image/png [:db_insert_placeholder_4] => 22858 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1425871274 [:db_insert_placeholder_7] => example-logo.png [:db_insert_placeholder_8] => image ) in drupal_write_record() (line 7239 of /hermes/waloraweb096/b2029/moo.canine/example/includes/common.inc).

I'm not sure why it's doing this. Will that patch work for this and if so, how do I apply it? Still new to Drupal.

attila.fekete’s picture

@DamienMcKenna yes, and I also thought that the issue comes up when chunks are being splitted across multiple web servers. But the reason I proposed the patch is that I was having the same problem in a different environment (locally as well).

attila.fekete’s picture

Made some changes to the initial patch to display a message about the failure instead of throwing an exception.

attila.fekete’s picture

Re-rolled against latest dev and fixed an issue with messages not being displayed in some cases.

Chris Matthews’s picture

Status: Needs review » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team