I'm setting up a new site, and whenever I upload an attachment I get an error similar to the following (the specific numbers change):

user warning: Duplicate entry '23-3' for key 1 query: INSERT INTO upload (fid, nid, vid, list, description, weight) VALUES (3, 23, 23, 1, 'test.txt', 0) in /var/www/cirrus/drupal-6.8/modules/upload/upload.module on line 411.

Now the thing is, if I look at the upload table before I do the upload, there is no such entry, and after there is. So there's initially no duplicate, which is very confusing.

I have a multi-site setup, and the other site doesn't have this problem. I also have a stand-alone site on another machine w/out this problem. So it's hard to claim it's a drupal or mysql bug, but it is really perplexing!

I've configured both to use the same modules, etc (though could have missed something) and only one is failing.

Any ideas where to look next?

thanks!

Comments

glowrocks’s picture

I remain convinced that the insert on line 411 of upload.module is being called twice for some reason. I really wish I knew why.

Since I don't, I modified the line by inserting "IGNORE" as shown below.

To begin, I emptied the db of all attachments so thatthe files or upload tables were empty.

I then did the saved the page with the attachment and the file showed up in both files and upload.

It worked with subsequent attachments as well.

Earlier I tested by running the raw SQL commands via phpmyadmin. With the original code shown above I got the same error. When I incremented the values appropriately, no error. So overall, I'm convinced the call is being made an extra time (or more).

Hope this additional info helps.

Here's the modified line 411 of upload.module

db_query("INSERT IGNORE INTO {upload} (fid, nid, vid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $file->fid, $node->nid, $node->vid, $file->list, $file->description, $file->weight);

I think this is a safe use of INSERT IGNORE. The data is being written to the db, the error is consistent with an extra attempt to write. There are other parts of the upload module that seem to deal w/real updates, which is the case the IGNORE ignores.

Super G’s picture

I'm on Drupal 6.8 and I'm having this problem as well. Any insights would be appreciated.

chuckdeal97’s picture

Are you using the inline module? I'm using Inline 6.x-2.x-dev and I think that is the culprit. You can follow along with #406462: nodeapi update/insert cause node_save to be called twice and see if I'm right.

Bryan76’s picture

Yup, I agree, inline api is causing the problem. However I have been unable to figure out how and or why it is.

slosa’s picture

- same problem. Only on new page creation does not happen on upload to an already existing page.

jgreep’s picture

I've found that the workflow module causes the same problem.

HumanTex’s picture

Also posted here before I found this posting... http://drupal.org/node/835378

As others have mentioned, my errors have been coming from another module whenever it calls for uploads via core. In my case it was job_posting - but - my guess is that it's not the calling modules alone that are causing upload to pump out errors. I have edited, removed, and re-added an attachment and haven't gotten the original dupe error or any others. It only appears (for me) when the node is first created and an upload is included as part of that first entry.

The only caveat I can think of is that I also use the content_approval module, so it may be interrupting the normal upload and save process somehow. i.e., when the node is approved/published on adding, it doesn't generate those initial errors at node creation. Is anyone else also using it to confirm that as a possible culprit?