# Can't undelete category description posts created by deleted user

**URL:** <https://meta.discourse.org/t/cant-undelete-category-description-posts-created-by-deleted-user/173696>\
**Category:** Bug\
**Created:** [December 18, 2020, 11:36am UTC](https://meta.discourse.org/t/cant-undelete-category-description-posts-created-by-deleted-user/173696 "2020-12-18T11:36:01Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)\
**Post date:** [December 19, 2020, 3:29am UTC](https://meta.discourse.org/t/cant-undelete-category-description-posts-created-by-deleted-user/173696/3 "2020-12-19T03:29:22Z")

</div>

I was able to run through it quickly just now and repro the same results.

1. Create a category with an admin user
2. Revoke their admin status and delete the user
3. The “About” topic for the category is soft-deleted when the user is deleted
4. Attempting to undelete/restore the topic doesn’t work
5. Changing ownership does technically work, but the topic remains in a strange deleted state no matter what you do from the UI.

From the console it looks like the `posts` record that is associated with the topic is deleted when the user is deleted. The topic record has a lot of 0’s when looking at various post related attributes.

It might be worth having an engineer see if we can be a bit more graceful here, but I suspect it’s easier said than done.

* * *

I was able to come up with a workaround to get back into a good place, but I had to use the command line. @jrivettcsa I would recommend taking a backup before you try this:

**Values needed**

- Category’s “About” topic ID  
Given [https://example.com/t/topic/1827](https://example.com/t/topic/1827), that would be `1827`

- Category’s ID  
Given [https://example.com/c/category-slug/5](https://example.com/c/category-slug/5), that would be `5`

Be sure to copy any of the content of the About topic you want to use later into a notepad or similar, then proceed with the following:

Enter the rails console

```plaintext
cd /var/discourse
./launcher enter app
rails c

```

Replace `<ABOUT_TOPIC_ID>` in the command below with the Category’s “About” topic ID, then run to hard-delete the broken topic.

```plaintext
Topic.where(id: <ABOUT_TOPIC_ID>).destroy_all

```

Press the q key to get back to the console if needed

The category is still associated with the bad topic, so we need to clear that out. Replace `<CATEGORY_ID>` in the command below with the Category’s ID, then run.

```plaintext
Category.where(id: <CATEGORY_ID>).update_all(topic_id: nil)

```

Press the q key to get back to the console if needed

Exit the rails console and run following rake task to create a new About topic for the category:

```plaintext
exit
rake categories:create_definition

```

Now that category should be fixed! You can rinse and repeat as needed.

---

_[View the full topic](https://meta.discourse.org/t/cant-undelete-category-description-posts-created-by-deleted-user/173696)._
