Hi,
I just ran into a major desaster with the 'Flag' module after installing the 'flag_weight' module for the first time (which is recommended on the 'Flag' project page, so I considered it to be safe). First I downloaded and installed the 'flag_weight' module, enabled it, and ran update.php, as ususal, even if this module does not come with any schema extensions. Also cleared the cache via Drush (drush cc all).
I didn't bother with the new module but went straight to ./admin/build/flags to add a new flag (a flag to mark favourite movies). I went through the configuration screens, but no new flag was created. I can not tell if flag 6.x-2.0-beta6 would have been capable to create new flags on this site because I never tried this; the flags I'm using were created with flag 6.x-1.3 or earlier.
I retried two times more, then the 'abuse_node' flag suddenly lost the enabled content types (it somehow reset from several enabled roles to one (authenticated user), and lost all content types except for 'story').
Next I edited the 'abuse_node' flag, added the lost user roles, and content types. After saving this flag, a red alert popped up, saying "This view is looking for a flag by the name "network", but there is no such flag. Perhaps it was deleted. Please update the relationship "Flags: network ..." in this view to use an existing flag." The flag the error message was referencing to is used in a View that is used on every page on my site, including the admin pages; the reported error probably did not relate directly to the editing operation on the 'abuse_node' flag, but saving this this flag oviously deleted another flag. And indeed, the custom "network" flag was gone from ./admin/build/flags. Next I checked the database:
mysql> select name from flags;
+--------------+
| name |
+--------------+
| abuse_node |
| lesezeichen |
| merkliste |
| produktdaten |
+--------------+
4 rows in set (0.00 sec)
The custom 'network' flag has been erased from the database, without my doing. When looking at the database table, panic started to creep up my spine as important site logic is based on the vanished flag (it instructs essential views what to show). Since this flag is gone, the view broke, and the wrong content is displayed to wrong users. At least for my use case this is a catastrophy.
And it's getting worse. I have an export of the vanished flag (as I said, it's important for my site, so I have a backup); when trying to import this exported view, I'm getting a WSOD (blank screen, without error message in watchdog log).
To summarize: At this point, I can not create a new flag; an existing flag has been deleted, and this breaks an important part of my site's logic; I can not import a backup of the flag; and I can not create a "new" flag with the "old" name to fix the view. I can not even edit the View as Views does not allow me to delete the relationship on the vanished flag. A total nightmare.
Versions used: I'm running flag 6.x-2.0-beta6 (instead of 6.x-1.3 because of #1302480: Unflag does not work which broke the stable release on all production sites); flag_abuse 6.x-2.0-rc1 (enabled); flag_friend 6.x-1.0 (installed, but not enabled); flag_terms 6.x-1.0-beta2 (installed, but not enabled); flag_weights 6.x-1.1 (recently installed and enabled); also I'm running Views 6.x-2.x-dev because of #1331032: Empty rewritten fields are not hidden anymore plus additional patch; however, probably I'm not running into #1335604: Flag 1.3 doesn't work with views 6.2.14 because I already use the dev release. Other environment: Pressflow 6.22.x, Memcache, APC, Boost, css_gzip, and javascript_aggregator.
My mental state currently does not allow any constructive attempts to reproduce the desaster. I think I'll now get wasted and add other findings with a hopefully clearer head tomorrow.
Thanks for any ideas or suggestions about what could trigger things like deleting configured flags, or not allowing me to add new flags (I'm using flags on this site for over two years without any incident except for the already mentioned #1302480).
Comments
Comment #1
asb commentedQuick update: I just tried to add a new flag on another site with flag 6.x-2.0-beta6. That results in a green message, saying: "Flag testflag was saved" (localized interface; original message text is probably:
Flag @name has been saved), but "testflag" is neither listed at./admin/build/flags, nor saved to the database. So the issue already starts with a vanilla flag 6.x-2.0-beta6.Comment #2
asb commentedUpgraded to 6.x-2.x-dev on the affected site. The (sub-) issue "Can not create new flags" exists here as well. When trying to import an an exported flag from 6.x-2.0-beta6, I'm not getting a WSOD with this version; the behaviour is identical to the manual creation: Positive confirmation message, but no flag is saved to the database. If the export is somehow modified, I'm not getting a refusal message (like in Views) but the WSOD.
Also verified the sub-issue on several other sites that were upgraded from 6.x-1.3 or earlier to 6.x-2.0-beta6. All those sites are affected and do not allow to configure new flags; behaviour as described in #1.
The "Can not create new flags" issue does not appear on sites where the 'flag' module has not been upgraded or where still flag-6.x-1.3 is used. Very nasty in combination with #1302480: Unflag does not work, though :-(
Comment #3
quicksketchI can't really say why a flag would suddenly disappear. Considering the variety of flag related modules and patches on your site, it's going to be very difficult to reproduce such a problem. However as far as the upgrade path from 1.3 to 2.x being broken, it's possible that this is the case but last I tested it (just before making the beta6 release), it was working fine. I recall that other users had reported that their flag table somehow lost its auto-increment property on the FID column. The problem you're describing sounds the same. Actually that problem might also explain a flag going missing entirely, if you have two flags in the database with an FID of 0, one of them might not show up.
However we've tried to fix this several times in the past, but somehow the update fails (silently) even though it works for most users. Perhaps it's an oddity with some versions of MySQL, I'm not sure. For reference:
#420250: Flag D5->D6 Update Doesn't Add Auto-increment to flags.fid Column
#715382: FID auto-increment missing from flags table on upgrade
#629396: Data upgraded from D5, no flags.fid field not set to auto_increment
Comment #4
asb commentedThanks for the reply.
Indeed... On the affected site:
On a unaffected site:
So what's the suggested action - uninstall 'flag' and related modules, drop the 'flag'-related tables (flag_content, flag_counts, flag_types, flags), and start from scratch on all sites with broken "auto_increment" ?
Or maybe something like
alter table flags add fid Int NOT NULL AUTO_INCREMENT key;orALTER TABLE flags AUTO_INCREMENT = 1might work (just suggestions from Googling around the MySQL manual)?Rerunning
flag_update_6002()(referenced in #420250: Flag D5->D6 Update Doesn't Add Auto-increment to flags.fid Column) gives me on the affected site:Whoops?
Comment #5
quicksketchWell I think you may have it right there. If update 6002 failed for you the first time but you (or whoever ran the update) didn't take notice, then that's the cause of all your troubles. But it's hard to say at this point. You can ever re-run updates a second time and expect them to work, because your database has already been modified. A this point I think you've pretty well hosed your database, but it's still possible to fix it manually be going through and manually making all the indexes/keys/columns.
In any case, I'm still at a loss for why this problem occurs. I can install Flag 1.3 and upgrade it to 2.x without any troubles at all. We've even added the update to add the auto-increment column twice (just in case the first onen didn't work), but even that doesn't solve the problem if something is preventing the index from being created.
Comment #6
asb commentedI don't know enough about the database structures of the 'flag' module to offer real help with this, but at least on almost all my sites where I have updated to 6.x-2.0-beta6 from flag 6.x-1.3 or earlier the error is consistent. I compared the 'flag' table on a rough dozend of sites, and the structure almost always looks like this:
On these sites I'm not using anything but a vanilla 'flag' module (no flag-related modules), so at least this sub-issue definitely can not be caused by an interference between flag "core" and flag "contrib".
Regarding the MySQL version: I'm running Ver 14.14 Distrib 5.1.49 from Debian GNU/Linux 6.0 "Squeeze", so that's not much out of the ordinary, also.
Since 'flag' does not depend on other modules (like 'ctools'), what could interfere with database updates except Drupal core?
Regarding rerunning
flag_update_6002(), I understand that running those updates a second time might not [can not|will not] work; however that's a bit surprising since that's the way major CCK updates (e.g. from D5 to D6) were accomplished: Keep rerunning update.php, until all errors are gone. Considering that and regarding the update errors quoted in #4, I don't see an attempt to alter the field "fid" in the "flag" table (if I'm even looking at the right database table, and if I tried to rerun the right database update).Well, I'm afraid this is clearly out of my league, but at least I can offer a pretty consistent testbed, in case you try to add the auto-increment column a third time, or something like this ;)
Regarding the one site with 6.x-2.0-beta6 that actually has this
auto_incrementproperty, the only major configuration difference compared to my other sites is that this site hadn't the 'boost' module enabled. But is it even theoretically possible that some module tampers with the ability of Drupal core to update the database schema??Comment #7
quicksketchHm, I'll need to give this more research. I doubt boost would be the source of the problem.
Comment #8
asb commentedSorry for burdening you with more work :-(
Again, I'm willing to provide any help I can give, including access to database dumps in various stages, if that helps.
Comment #9
asb commentedOK, before dropping 'Flag' completely, I tried this:
That gives me this schema:
However, I'm still at a loss what "manually making all the indexes/keys/columns" actually would require. It would really help to get some instructions which tables and/or fields need to be modified as well.
Please note that the field "content_type" has Null=YES, by my unaffected site has Null=No. I don't know what the correct definition would be.
However, the SQL one-liner gives me the following changes:
Is it really that easy?
PS: Since the issue queue has numerous issues related to schema changes, maybe it would help to verify the current schema at some point. This could notify the user about problems, for example, at the status report page (
./admin/reports/status).Comment #10
asb commentedAlso, for the sake of the experiment I set up an older version of the affected site and directly updated from 6.x-1.3 to 6.x-2.x-dev. But I executed the SQL statement from above (
ALTER TABLE flags CHANGE COLUMN fid fid int(10) unsigned NOT NULL auto_increment;) before running update.php/drush updatedb (!) When runningdrush updatedb, this gave me:All updates were run successfully, and no errors were indicated. Final table schema:
Maybe that little line of SQL is the manual fix?
Comment #11
quicksketchThere's a module that serves a dedicated purpose for this: http://drupal.org/project/schema
Comment #12
socketwench commentedClosing, since the issue could not be reproduced. Sorry!!!