Strange. When trying to update one computed field it gets not updated. Instead the following error is logged for each node:
Duplicate entry '1343' for key 'PRIMARY' query: INSERT INTO content_type_publication SET `field_journal_doi_url_value` = '<a href=\"http://dx.doi.org/10.1016/j.tifs.2011.11.005\" target=\"_blank\" title=\"Digital Object Identifier (DOI)\">10.1016/j.tifs.2011.11.005</a>', `vid` = 1343, `nid` = 511 in /etc/drupal6/all/modules/computed_field_tools/computed_field_tools.module on line 204.
The computed code in question is:
$doi = $node->field_journal_doi[0]['value'];
$url = 'http://dx.doi.org/' . $doi;
$out = '<a href="' . $url . '" target="_blank" title="Digital Object Identifier (DOI)">' . $doi . '</a>';
$node_field[0]['value'] = $out;
Comments
Comment #1
andjules commented+1 on the 7.x verion
Integrity constraint violation: 1062 Duplicate entryComment #2
PatchRanger commentedI got the same error recently.
Reason :
We are quering a count of rows that look like our to decide whether we need to insert it or to update.
The bug is in the conditions, they are to strong, we don't ever find anything.
Count is always 0, we are trying to insert - and catching an error about duplicate primary key value.
How to solve :
Delete "Bundle" from query conditions because it IS NOT IN PRIMARY KEY.
Please review the patch.
I have tested it myself - it works.
Comment #3
PatchRanger commentedComment #4
PatchRanger commentedDiscovered that we need to delete this too strong condition from db_update also.
Otherwise we got no errors but no updating too.
Tested on self skin. :)
Please review.
Comment #5
roball commentedThanks for the patch, Staratel. Could you please also attach a 6.x compatible patch?
Comment #6
PatchRanger commentedWe should not port it until we receive feedback about 7.x version.
Also I don't have D6 installed to see what is the problem there and how to port this patch.
Robert, I recommend you to look into these lines :
You should debug them to find the problem in 6.x case.
Hope it helps.
Comment #7
wizonesolutionsThis didn't work for me. I still get:
The weird thing is that it's even trying do an
INSERT. The field almost certainly already exists. I'll dig in a bit and see what I can find.Comment #8
wizonesolutionsActually, this might be a data issue on my own site. I suspect it's the same for others. In any case, setting back to
needs review.Comment #9
wizonesolutionsOK, it's actually this one: #1587676: Not setting language field
Comment #10
frakke commentedIt should be fixed with the latest build in the repository, HEAD at 7.x-1.x. The patch didn't fix anything.
Comment #11
roball commentedThanks for fixing it for D7. Could you please also commit to 6.x-1.x?
Comment #12
frakke commentedSure
Comment #13
frakke commentedThe 6.x-1.1 version of the module should be available shortly for download. It addresses this issue and adds a few other features/fixes.
Comment #14
roball commentedThanks frakke, v6.x-1.1 seems to work fine.
Comment #15
organicwire commentedFor me there's still an error when recalculating. After a fresh module install, recalculation fails with the following error:
I'm using the latest dev snapshot for D7.
Comment #16
organicwire commentedDid patch in #4 really go into the code? It doesn't look like to me.
However, as the error occurred in my drupal installation too, it was caused by another thing. When writing back the computed value into the db, we test if the field will be updated or inserted. Here a wrong compare operator is used:
Thus, having a zero value in an existing field, we go for inserting because empty(0) returns true. Instead we should write
My patch fixes this.
Comment #17
kmajzlik commentedI can confirm bug/error in 7.x-1.0
I can confirm that patch attached in #15 works like a charm - please commit it ASAP and create 7.x-1.1 version.
Comment #18
kmajzlik commentedComment #19
roball commentedkarlos007, you mean the patch attached to comment #16 fixes this issue? If so, I would suggest to also update this issue's Status accordingly.
Comment #20
kmajzlik commentedroball: you are right. my mistake, it was late night here and (i dont know why) i thought that tagging RTBC is enough...
Comment #21
Island Usurper commentedWhile I agree that this patch works, wouldn't it be better to use db_merge()? In the worst case, it's still doing two queries, but it makes the code simpler and easier to read.
Comment #22
GerZah commentedPatch #16 works fine for me. Thanks!
Comment #23
roball commentedComment #24
frakke commentedThis issue should be solved from 7.x-1.1-rc1 and forth.
Comment #25
frakke commented