Hi , I'm running Drupal 6.14
the following error appear during updating and inserting
Duplicate entry '14-0' for key 1 query: INSERT INTO image_attach (nid, iid, weight) VALUES (14, 0, 2) in ....sites/all/modules/image/contrib/image_attach/image_attach.module on line 349.
The result in Db is
nid iid weight
14 0 1
14 19 0
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 607444-image_attach_iids-1.png | 46.28 KB | joachim |
| #7 | image_attach-607444-1.patch | 3.56 KB | recrit |
| #5 | image_attach-607444.patch | 3.52 KB | recrit |
Comments
Comment #1
joachim commentedWere you just saving a node? Or were you doing something else?
This is an error that crops up on updating the module: #207557: update 5-1 to 5-2 gives user warning: Duplicate entry '611-thumbnail' for key 1 query in image_update_5200 but I'd be interested to hear about other things that can (more reliably!) produce it.
Comment #2
iko commentedI got this error message with the same circumstances ; it seems to occur when the "attach existing images" option is activated. The "line with the problem" in image_attach/image_attach.module is 281 when attaching the image and 358 when saving/updating the node (the node the image is attached to).
There is no problem when "attach existing images" is not activated.
Comment #3
joachim commentedYou definitely have a 0 for a iid?? That's not normal at all!
Comment #4
iko commentedThe first image created through image_attach had an iid = 0, yes. Then the number was correct.
Comment #5
recrit commentedthis issue occurs because the iid = 0 ('None') gets saved to the node regardless of image_attach_node_form_submit() removing
unset($form_state['values']['iids'][0]). Then image_attach_nodeapi operates on $node->iids which has the iid=0 saved in it.Fix:
Validate iid and nid before inserting into db table. INSERT happens in more than 1 place, so I have created a wrapper function (_image_attach_write_record) to insert into the table and utilize drupal_write_record. This makes a common handler for inserting per the defined schema, ie create the record and check if the primary key already exists or not. Since this is now a common function, we can pull the weight incrementing into it to simplify some of the surrounding code when going to insert... so now you just have to call
_image_attach_write_record($nid, $iid).Comment #7
recrit commentedoops.. original patch was in the image_attach directory.
Here's a re-roll from the image directory.
Comment #9
joachim commentedCould you compare with the patch over at #747900: warning: array_filter() The first argument should be an array ... image_attach.module on line 349 please?
> this issue occurs because the iid = 0 ('None') gets saved to the node regardless of image_attach_node_form_submit() removing unset($form_state['values']['iids'][0]). Then image_attach_nodeapi operates on $node->iids which has the iid=0 saved in it.
I'm not managing to reproduce this. Can you give your exact steps please?
Comment #10
recrit commented747900 seems to a address a different issue. My submitted patch addresses the original issue above that occurs when the option 'None' is selected as well as 1 existing image is selected. It will reproduce the error as stated above:
An image_attached gets saved for iid = 0 and then it attempts to insert again.
I am not sure why the patch has failed, it is off of the latest dev.
Comment #11
joachim commented> when the option 'None' is selected as well as 1 existing image is selected.
Like this?
I'm still not able to reproduce your error.
Comment #12
recrit commentedyes, just like that... only difference is that I am using the BetterSelect module.
I just uninstalled betterselect and tested with original image_attach code and everything works fine. I can't quite pinpoint where the betterselect module causes this conflict, but it does.
Comment #13
joachim commentedThis is not the first time I've seen BetterSelect break things. File a bug report on BetterSelect :)
Comment #14
recrit commentedupdated title and moved to Better Select issue queue as active
Comment #15
andrebonfanti commentedsubscribe