Download & Extend

Duplicate fid-node key error when flagging content

Project:Flag
Version:7.x-2.0-beta6
Component:Flag core
Category:bug report
Priority:major
Assigned:Unassigned
Status:active

Issue Summary

When flagging content via AJAX. Occasionally when flagging content I get a 500 error. I have not been able to 100% predict when the error occurs, but do I seem to get it more frequently after I flush the cache

My database log shows the following error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-49' for key 1: INSERT INTO {flag_counts} (fid, content_type, content_id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => node [:db_insert_placeholder_2] => 49 [:db_insert_placeholder_3] => 2 ) in flag_flag->_update_count() (line 739 of ../sites/all/modules/flag/flag.inc).

Let me know if you need anything else to pin it down.

Comments

#1

Status:active» needs review

i was having this bug too, here is a patch of my solution.

AttachmentSize
Duplicate_fid-node_key_error_when_flagging_content.patch 956 bytes

#2

I was experiencing the same error, the patch above seemed to solve this problem.

#3

Priority:normal» major

Hi

Please commit this

From documentation for update queries: http://drupal.org/node/310080

The execute() method will return the number of rows affected by the query. Note that affected is not the same as matched. In the above query, an existing record that already has a uid of 5 and status of 1 will be matched, but since the data in it does not change it will not be affected by the query and therefore not be counted in the return value. As a side effect, that makes Update queries ineffective for determining if a given record already exists.

Scaling to major as 500 errors on live sites is a NO NO NO

#4

Status:needs review» fixed

Thanks jodarove for the patch and nirbhasa for reporting the problem. I discovered this issue separately as part of #1258282: Logging in after anonymous flagging may cause duplicate entry SQL errors, but it doesn't look like I got the syntax for a db_merge() query correct. I've committed this patch that fixes the current 7.x-2.x branch to match your approach, which is correct.

AttachmentSize
flag_count_fix-d7.patch 565 bytes

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#6

Status:closed (fixed)» active

I had the same issue in carnity.org for flagging content with anonymous user, so used the above patch and problem resolved.

Now new problem appear, that might have been there before but i just noticed today. When anonymous user flag content and do the comparison and content stay flagged, then if anonymous user wants to login then it shows similar type of PDO error but in flag.module. Can you please help resolving this bug???? Thanks in advance.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-7-1-0' for key 'fid_content_id_uid_sid': UPDATE {flag_content} SET uid=:db_update_placeholder_0, sid=:db_update_placeholder_1 WHERE (uid = :db_condition_placeholder_0) AND (sid = :db_condition_placeholder_1) ; Array ( [:db_update_placeholder_0] => 1 [:db_update_placeholder_1] => 0 [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => 20 ) in flag_user_login() (line 573 of /home/thehighb/public_html/carnity.org/sites/all/modules/flag/flag.module).

#7

Version:7.x-2.x-dev» 7.x-2.0-beta6

Same too me
thanks

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-38' for key 1: INSERT INTO {flag_counts} (fid, content_type, content_id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => node [:db_insert_placeholder_2] => 38 [:db_insert_placeholder_3] => 1 ) en flag_flag->_update_count() (línea 738 de ../drupal/sites/all/modules/flag/flag.inc).

#8

Same problem with me.