Cancelling an account (Delete the account and its content) is impossible. An error occurs:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?render=overlay&id=78&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value adjusted for column 'count' at row 1: UPDATE {flag_counts} SET count=:db_update_placeholder_0 WHERE (fid = :db_condition_placeholder_0) AND (content_id = :db_condition_placeholder_1) ; Array ( [:db_update_placeholder_0] => -1 [:db_condition_placeholder_0] => 2 [:db_condition_placeholder_1] => 198 ) in flag_user_account_removal() (line 621 of .../sites/all/modules/flag/flag.module).

Manually unflagged all of the user's flags, but it did not help.
I am in the process of handing over this new website to the customer and would love to have cancelled all test accounts.

Comments

quicksketch’s picture

Title: Impossible to cancel account: AJAX HTTP error, PDOException, flag.module » Flag may attempt to decrement flag_counts below 0, causing PDO error (while deleting accounts)
Priority: Critical » Normal

I don't think deleting accounts is "impossible" in all situations, but it does reveal a bug in our incrementing/decrementing of counts. You can solve this problem in the short term by simply emptying the flag_content and flag_counts tables for whatever flag is causing the problem (looks like FID 2).

DELETE FROM flag_content WHERE fid = 2;
DELETE FROM flag_counts WHERE fid = 2;

Note that this problem does not always occur. I can delete and add accounts just fine. The reason you're running into this problem is because Flag is attempting to decrement a count below "0", which isn't allowed by our database schema. I'm not sure what could cause this situation, but we should prevent Flag from attempting to do such a SQL query in the first place.

Tino’s picture

Thanks you quicksketch, deleting those records solves it!
You are right, it is not "impossible" in all situations. I have also been able to delete users without this problem occurring. I should have said something like "Cancelling a certain account is impossile"....

janchojnacki’s picture

Removing rows from the DB each time when error appears is not solution. Created patch.

joachim’s picture

Status: Active » Needs review
joachim’s picture

Version: 7.x-2.0-beta6 » 7.x-2.x-dev
Status: Needs review » Fixed

We already cover this possibility when an object is unflagged, BTW:

  */
  function _decrease_count($content_id, $number = 1) {
    // Delete rows with count 0, for data consistency and space-saving.
    // Done before the db_update() to prevent out-of-bounds errors on "count".

Committed with code style tweaks.

Issue #1362260 by jaanhoinatski: Fixed user account deletion potentially causing out of bounds PDO error when decrementing flag counts.

joachim’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Fixed » Patch (to be ported)

Probably needs a backport, but patch will need considerable work to apply on 6-2.

joachim’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.16 KB

*sigh* This is now holding up the 6-2 beta 8.

Can anyone give it a quick review?

socketwench’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Tests clean.

joachim’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Committed.

Applies cleanly to 6-1 too.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Typos