I'm having a strange error:
user warning: Duplicate entry '4372' for key 1 query: INSERT INTO i18n_strings (lid, type, oid, property) VALUES(4372, 'empty', 0, '0') in /sites/all/modules/i18n/i18nstrings/i18nstrings.module on line 247.
This error appears on different pages when administering content, such as editing a node, but I've seen it appearing on different places. Also the entry value (here 4372) varies, but the rest of the message is always the same. It does not limit functionality, when I refresh the page the error appears on everything works, but it annoys me. Any ideas how to fix this, and where it's coming from?
Comments
Comment #1
ar-jan commentedHm, in the end the solution was quite simple. With phpmyadmin I just dropped all records in the i18n_strings table. That solved all errors. (I had been getting more and more of such errors, when just editing a node or something that had nothing to do with any translated string). No idea where all this came from.
Strange side-effect was that for one content type I have, the selected taxonomy term was unselected for some posts.
Comment #2
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #3
eMPee584 commentedI have had the same issue.. this definitly should have a line in the documentation, never would have suspected that emptying that table might fix it... but this obviously would drop any customized stings IIUC.. should there not be a different fix for this?
And what exactly is going on, the troubling field is deleted in the previous line but then it complains about a duplicate entry?
Comment #4
eMPee584 commentedAHA... it's a
race condition
that is occuring here.... mmhhh .... so there's no quick fix other than regularily running
DELETE FROM `watchdog` WHERE `variables` REGEXP 'Duplicate.*INSERT.*i18n'...Comment #5
jose reyero commentedNot for the handbook, this is a bug, to do more research...
Comment #6
eMPee584 commentedit is not a bug, it happens when the same page is accessed by multiple users at the same time. To prevent this from happening, the table has to be locked. I believe this is planned for D7.
Comment #7
jose reyero commentedTrue, it's some race condition, which seems to be all around Drupal.
Anyway, implemented some workaround, this should avoid more error logs
Comment #8
quicksketchI don't understand why this problem can't be fixed. If it's a race condition (which I agree, this does look like the case), the solution is to fix the race condition, not clear the table! This simple patch removes the race condition and doesn't increase the number queries. Instead of doing a DELETE/INSERT it does a SELECT/UPDATE. This problem was flooding our site's watchdog with thousands of entries per hour.
Comment #9
eMPee584 commentedthe patch didn't apply to the head version but it was not overly complicated to do it manually. It works and looks like the right way to do it, good job quicksketch. (Cool, now i know how to fix an SQL race condition ;)
Comment #10
neclimdulAlternate version of the patch based on the solution used by cache_set and variable_get in d6
Comment #11
eMPee584 commentedEven better, one less SQL query. You're the dudes folks. Here's the patch rerolled for HEAD.
Comment #12
nedjoAgreed, this is the correct fix.
Comment #13
quicksketchThere's no need for the @ symbol before the call to db_query(), this could obscure problems in the future if the query does cause errors, they shouldn't be suppressed. Was there are reason for adding this neclimdul?
Comment #14
nedjoneclimdul was following the code in variable_set() and cache_set(), which both use the @.
This was introduced in #55516: Remove database locking.
Comment #15
quicksketchSeems like David Strauss added the @ in #130 though the reason was never stated. I'll ask him about this need, but my guess is that it is unwarranted, just the result of following a pattern that existed before the locking was fixed (perhaps the @ was necessary at one point if a race condition were causing errors).
Comment #16
eMPee584 commentedWell whatever the @ means, the fix is ready to be committed.
Comment #17
neclimdulit suppresses errors
http://www.php.net/manual/en/language.operators.errorcontrol.php
Comment #18
quicksketchI agree we can go ahead and commit this. When I satisfy my curiosity about the @ sign, I'll make a patch for core first if it can be safely removed (my feeling is that it can), though as nedjo points out, all this code is gone anyway in Drupal 7 thanks to the new database layer.
Comment #19
nedjoThis issue indeed is worth fixing; but it suggests incorrect calls elsewhere to the tt() function.
tt() can be called in two ways--to add or update a string to be translated or to fetch an existing translation (if there is one).
The fact that we're getting high volume write operations suggests that insert/update operations are being called inappropriately.
It would help to know just what queries are failing, so we can track these issues to their source.
I had a look around and found this issue in i18nmenu: #339057: Performance: menu translations continuously updated, which was one instance of updating instead of fetching. The patch there may help reduce these errors.
All of which suggests that we shouldn't suppress error messages--they're indicators for where we need to fix other code. So let's leave out the @.
Comment #20
nedjoLikely we are indeed getting race condition errors. But looking again at the original error message above, it seems noteworthy that the particular string being inserted is 0. A possible cause is:
* for whatever reason, we have a 0 being passed to tt().
* the first time this happens, a record is created
* the next and all subsequent times, the query to find an existing translation returns 0, which is interpreted as not finding a translation, so a new insert is attempted
* the new insert fails, because there is an existing record.
Probably we should bail early when an empty value is passed to tt(). We may also need handling of this case elsewhere.
Comment #21
catchI have a feeling the @ might be to help with replication, but that's only half-remembered. Will be interested to see what the answer actually is.
Comment #22
nedjoI committed a version of the patch without @ and left a code comment.
Setting to needs more info pending more information on the @ question.
I looked further at the code and concluded we can't suppress empty values, since they're used to trigger deletes.
Comment #23
jose reyero commentedThanks nedjo, this looks much better now. Also committed a related patch which may avoid unneeded updates, #339057: Performance: menu translations continuously updated
About the @db_query(), I've added it back, reasons commented on the code. Otherwise we'd need an extra select statement to check if the value is already there. This will allow people to use the module while we (developers) can look for better options here.
The weird values passed around may come from other modules using i18nstrings, for further investigation....
Comment #25
hass commentedMarked #369734: user warning: Duplicate entry '4478' for key 1 query: INSERT INTO i18n_strings (lid, type, objectid, property) as a duplicate.
Comment #26
helloanshul commentedm having similar problem on my website