# Old user suspension reasons have gone missing

**URL:** <https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305>\
**Category:** Bug\
**Created:** [2015年十二月31日 05:42 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305 "2015-12-31T05:42:12Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)\
**Post date:** [2016年一月7日 23:28 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/21 "2016-01-07T23:28:57Z")

</div>

Yeah, just 3 users, so no issues with the quick fix. Still wondering what you are referring to as a “migration artifact”?

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2016年一月7日 23:33 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/22 "2016-01-07T23:33:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2016年一月8日 03:26 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/24 "2016-01-08T03:26:37Z")

</div>

It may take a few days or a week, but we will look into it and see what we can do.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月8日 03:59 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/25 "2016-01-08T03:59:22Z")

</div>

This commit by @techAPJ broke it:

[https://github.com/discourse/discourse/commit/4c967d11b46133861b8c9495eb65f727425f7dd5#diff-0a5ad2d838fbffeb0848dda1be5dbd12](https://github.com/discourse/discourse/commit/4c967d11b46133861b8c9495eb65f727425f7dd5#diff-0a5ad2d838fbffeb0848dda1be5dbd12)

```plaintext
     @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](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.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2016年一月8日 04:05 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/26 "2016-01-08T04:05:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)\
**Post date:** [2016年一月8日 04:08 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/27 "2016-01-08T04:08:24Z")

</div>

Thanks for hunting this down @sam. Will this fix restore the missing suspension reasons, or just prevent this from occurring again in the future?

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2016年一月8日 04:10 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/28 "2016-01-08T04:10:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月8日 04:11 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/29 "2016-01-08T04:11:46Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Lorne\_Kates](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@Lorne\_Kates](https://meta.discourse.org/u/Lorne_Kates)\
**Post date:** [2016年一月8日 04:12 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/30 "2016-01-08T04:12:02Z")

</div>

Is it possible to provide a fixing query… something like “update WHATEVER from (select WHATEVER from history table) … match on some ID”?

---

<div class="post-metadata">

**Author:** ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)\
**Post date:** [2016年一月8日 04:12 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/31 "2016-01-08T04:12:37Z")

</div>

Thanks for clearing that up. We have no suspensions in the last 21 days, so all is good! Much appreciated 😄.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月8日 04:13 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/32 "2016-01-08T04:13:36Z")

</div>

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](https://meta.discourse.org/t/enums-that-are-used-in-tables-need-to-be-stable/37622)

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [2016年一月8日 05:07 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/33 "2016-01-08T05:07:10Z")

</div>

I’ve updated and can confirm that:

- the [2289 year suspension mentioned previously](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/13) created before the bug has it’s reason restored.
- the [suspension created 6 hours ago](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/15) 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”:

 ![](https://global.discourse-cdn.com/meta/original/4X/a/7/9/a794d571d7d995876467935e4a81ebbcbe01c184.jpeg)

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月8日 05:11 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/34 "2016-01-08T05:11:06Z")

</div>

Give me a bit, coming up with a migration that will fix the majority of the pain.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月8日 05:55 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/35 "2016-01-08T05:55:51Z")

</div>

This will fix the vast majority of problems this generated

[https://github.com/discourse/discourse/commit/956e3ad2088a9ebe09338b94689f91d5975753e9](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.

---

<div class="post-metadata">

**Author:** ![calmh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/calmh/32/115466_2.png) [@calmh](https://meta.discourse.org/u/calmh)\
**Post date:** [2016年一月8日 07:25 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/36 "2016-01-08T07:25:42Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月8日 07:27 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/37 "2016-01-08T07:27:03Z")

</div>

Agree @neil can you do a new release tomorrow?

---

<div class="post-metadata">

**Author:** ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)\
**Post date:** [2016年一月8日 15:25 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/38 "2016-01-08T15:25:51Z")

</div>

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](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](https://meta.discourse.org/t/enums-that-are-used-in-tables-need-to-be-stable/37622)

---

<div class="post-metadata">

**Author:** ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)\
**Post date:** [2016年一月9日 03:18 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/39 "2016-01-09T03:18:55Z")

</div>

> [@DeanMarkTaylor](#):
>
> 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!

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!

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2016年一月9日 06:46 UTC](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305/40 "2016-01-09T06:46:31Z")

</div>



[上一頁](https://meta.discourse.org/t/old-user-suspension-reasons-have-gone-missing/37305.md?page=1)
