Yeah, just 3 users, so no issues with the quick fix. Still wondering what you are referring to as a “migration artifact”?
Yeah if you have lots of these permanently suspended users there is no quick fix. But if it is a few, should not be a problem to just unsuspend, re-suspend.
A migration artifact is a mistake in upgrading the database between Discourse versions.
Anyway now that @techapj has that information, perhaps he can dig a bit in the raw database to see if the data is still there on older instances where users were suspended. BBS is a good example and definitely exhibits this problem as well, all the old suspension reasons are gone.
It may take a few days or a week, but we will look into it and see what we can do.
This commit by @techAPJ broke it:
@actions ||= Enum.new(:delete_user,
:change_trust_level,
:change_site_setting,
:change_site_customization,
:delete_site_customization,
+ :change_site_text, <<<====
:checked_for_custom_avatar, # not used anymore
:notified_about_avatar,
:notified_about_sequential_replies,
@@ -33,26 +34,27 @@
:auto_trust_level_change,
:check_email,
:delete_post,
:delete_topic,
:impersonate,
:roll_up,
:change_username,
:custom,
:custom_staff,
:anonymize_user,
:reviewed_post,
:change_category_settings,
:delete_category,
:create_category)
Our enums go from 1 upwards, if you insert anything into the list like that (as opposed to appending at the end) you break everything.
I fixed the issue with
https://github.com/discourse/discourse/commit/3b45cd0fcb4d48f3166e05e3501cbbcb5805d59f
But anyone that updated in the last 21 days is going to have out-of-whack actions in user history, it is pretty much impossible to fix the broken window, cause I would have to join against a table that has version history.
Can you add comments in the code indicating the danger in inserting here? Feels like there should be a big WARNING there so this mistake does not happen again in the future.
Thanks for hunting this down @sam. Will this fix restore the missing suspension reasons, or just prevent this from occurring again in the future?
As stated above, any log table data changed (or created) in the last 20 days is broken forever because the enums were shifted down by the insertion. Data that was not changed in the last 20 days will be unaffected.
The fix will restore all the old ones, but the new suspensions that happened ever since the bug was introduced are impossible to recover. (21 day window)
Is it possible to provide a fixing query… something like “update WHATEVER from (select WHATEVER from history table) … match on some ID”?
Thanks for clearing that up. We have no suspensions in the last 21 days, so all is good! Much appreciated .
No it is not possible, we do not store the (git version + date it started running) in a table, if we had that information we could use a query to fix.
We will correct the underlying problem asap
https://meta.discourse.org/t/enums-that-are-used-in-tables-need-to-be-stable/37622
I’ve updated and can confirm that:
- the 2289 year suspension mentioned previously created before the bug has it’s reason restored.
- the suspension created 6 hours ago no longer has it’s reason.
Thanks for the fix!
Is there any weirdness we should expect or need to keep an eye out for?
You know - because of the “broken window”:
Give me a bit, coming up with a migration that will fix the majority of the pain.
This will fix the vast majority of problems this generated
https://github.com/discourse/discourse/commit/956e3ad2088a9ebe09338b94689f91d5975753e9
It looks for “auto change trust level” something that happens quite a lot being mislabeled as “check email” and for “impersonate” that was mislabeled as “check email”. Once it finds the bounds it takes one off the action number.
It logs what changes it makes in case we have to revert them. We can add a few more conditions but it should vastly improve the data quality.
Would it be a good idea to drop a new beta with this in, as the bug seems to be present in the current beta7? (I’m thinking as people are still installing and upgrading to beta7 out there.)
I apologize for introducing this bug. It was a stupid mistake.
As per @sam’s recommendation I have created a PR to change Enums to also accept a hash, and used it almost everywhere where stability is required along with test cases:
https://github.com/discourse/discourse/pull/3950
More details here:
https://meta.discourse.org/t/enums-that-are-used-in-tables-need-to-be-stable/37622
Just wanted to say thanks again…
… and after updating I can confirm that both the sample suspended users have correct reasons marked against them now - yay!