Greetings,

The usage of db_affected_rows() in cache_set() function causes the following problem:
When UPDATE query is performed and data is not changed in cache table db_affected_rows() returns 0 but not 1 despite the fact that the row was found. This happens because data was not literally affected. This feature of MySQL is described here www.phpfreaks.com/phpmanual/page/function.mysql-affected-rows.html

So, after UPDATE was performed on an existing row, INSERT also executes and we receive a 'Duplicate key' error because such $cid already exists.

It is better to change db_affected_rows() to something like this:
db_result(db_query("SELECT COUNT(*) c FROM {cache} c WHERE cid = '%s'", $cid))

You can reproduce this error by enabling any other language than english. I heard several people who developing non english sites receive such error too. This error depends on the other problem which I described here http://drupal.org/node/69027 - locale cache entry was not deleted and this bug can be easily reproduced.

Thank you.

Comments

beginner’s picture

Version: 4.6.6 » x.y.z

We have to make sure this bug doesn't exist in cvs, too.
The fix can then be backported to 4.7 and 4.6 later.

Drupal's multilingual support certainly should be improved ;).

beginner’s picture

http://drupal.org/node/66909 set as a duplicate of this issue.

This may be of interest:
http://drupal.org/node/65801

killes@www.drop.org’s picture

Status: Active » Closed (duplicate)

http://drupal.org/node/65801

The fix will be in 4.7.3.