# Permanent deletion bug

**URL:** https://meta.discourse.org/t/permanent-deletion-bug/231576
**Category:** Bug
**Tags:** permanently-delete
**Created:** [June 30, 2022, 3:09pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576 "2022-06-30T15:09:56Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [June 30, 2022, 3:09pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/1 "2022-06-30T15:09:56Z")

</div>

I think there is a bug with permanent deletion.

> [@Introducing permanently delete post functionality](https://meta.discourse.org/t/introducing-permanently-delete-post-functionality/207109):
>
> When a post is deleted in Discourse, we perform a soft-delete. This means that post is still present in the database in case an administrator wants to recover it later. A soft-delete is not sufficient when the deleted post contains sensitive information and must be pruned from the database completely. For those situations, we are introducing the ability to permanently delete a post. To use this feature, enable the can permanently delete setting. However, please be aware of the risks i…

I delete a couple of posts. Now I cannot open the deleted post list.

You can see here I still have 342 deleted posts. But when I click on it. It leads to a 404 page.

I can still open other user’s deletion list but not my own.

 ![Screenshot 2022-06-30 at 17.06.48](https://global.discourse-cdn.com/meta/original/4X/b/7/3/b73460c43db5ab88d7f2304b3d302825d5b76cbd.jpeg)

 ![Screenshot 2022-06-30 at 17.06.59](https://global.discourse-cdn.com/meta/original/4X/3/4/c/34c45351fbf50ce5c0b980b650e2148de4c999da.png)

Is there anything we can do to fix it?

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [June 30, 2022, 4:07pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/2 "2022-06-30T16:07:41Z")

</div>

Okay, I think I figured out the steps to recreate the bug.

I’m not sure you need two accounts but here is my situation:

1. Account A creates a topic, then pin and close the topic.
2. Account A soft deletes the topic.
3. Wait for 5 min, log into Account B, and open Account A’s deletion list (for example: [www.example.com/u/username/deleted-posts](http://www.example.com/u/username/deleted-posts))
4. Find the post Account A just soft deleted, open it.
5. If you try to permanently delete the post, it’ll show an error message: post can’t be deleted because there are other posts.
6. You need to delete the pin and close topic message below the post, then try permanently delete again.
7. You will succeed, but now you can’t open Account A’s delation list anymore.

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 2, 2022, 8:03pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/3 "2022-07-02T20:03:59Z")

</div>

Could someone take a look at this, please?

I was cleaning some posts that contain sensitive information and now we are stuck…

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [July 2, 2022, 9:32pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/4 "2022-07-02T21:32:35Z")

</div>

> [@VincentAlse](#):
>
> I was cleaning some posts that contain sensitive information and now we are stuck…

Can you still access the deleted posts from the topic/pm and permanently delete them from there, or can you no longer see your deleted posts at all?

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 2, 2022, 11:53pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/5 "2022-07-02T23:53:12Z")

</div>

I can access them from the post.

But since I don’t know which posts they are, the delete post list is critical.

Without it, I must manually go through all private messages and public topics to find them.

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 2, 2022, 11:54pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/6 "2022-07-02T23:54:55Z")

</div>

I tried deleted-posts.json too. But the information doesn’t contain deleted posts.

It only shows things like “user\_badges” and other user information.

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 3, 2022, 12:02am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/7 "2022-07-03T00:02:39Z")

</div>

If I can get a deleted post id list somehow that’ll help too.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [July 3, 2022, 7:53am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/8 "2022-07-03T07:53:17Z")

</div>

I’m trying for a repro:

- Admin A creates new topic, pins it globally (forever), and then closes it
- Admin A then soft-deletes topic  
  
- Admin B finds this topic by accessing Admin A’s `/deleted-posts` list from their profile
- Admin B attempts to permanently delete topic - receives a “You can not permanently delete this topic because there are other posts.” error
- Admin B deletes ‘pin’ and ‘close’ small action posts
- Admin B retries permanent delete - delete is succesful  
  
- However, Admin B now cannot access Admin A’s `/deleted-posts`, with an error of `GET https://greedy.jammydodger.monster/posts/jammydodger/deleted?offset=0`

Though Admin A and Admin C can still access Admin A’s `/deleted-posts` list. In the short term, @VincentAlse, could you use the secondary admin account to access the `/deleted-posts` list to find the other posts you wish to delete? Alternatively you could use a [data-explorer](https://meta.discourse.org/t/discourse-data-explorer/32566) query to identify them?

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 3, 2022, 8:48am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/9 "2022-07-03T08:48:15Z")

</div>

Hi @JammyDodger

Thanks for the confirmation. I just tried Admin C (with both old account and newly created account). It doesn’t work for me. I think the reason is that I was deleting posts for many different accounts and bugged the delete listed for most of them.

Let me take a look at data-explorer. Can I query deleted posts with it?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [July 3, 2022, 9:08am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/10 "2022-07-03T09:08:28Z")

</div>

Ah, that is unfortunate. If you have access to the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin I think something like this should replicate the `/deleted/posts` list for a particular user (with post\_id thrown in for good measure):

```plaintext
-- [params]
-- user_id :user_id

SELECT p.created_at AS reltime$time,
       id AS post_id,
       id
FROM posts p
WHERE p.user_id = :user_id
AND p.deleted_at IS NOT NULL
ORDER BY p.created_at DESC

```

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 3, 2022, 9:46am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/11 "2022-07-03T09:46:50Z")

</div>

Let me give it a try.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [July 4, 2022, 11:33am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/12 "2022-07-04T11:33:54Z")

</div>

Did that work out for you @VincentAlse? I think there should be multiple ways to find the posts you want to delete if that one didn’t give you the list you needed?

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 4, 2022, 9:48pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/15 "2022-07-04T21:48:37Z")

</div>

A dumb question. What is user\_id? I think my user\_id is 1 based on the .json page.

I get this message: ActiveRecord::PreparedStatementInvalid: missing value for :user\_id in /\*

 ![Screenshot 2022-07-04 at 23.46.50](https://global.discourse-cdn.com/meta/original/4X/e/c/5/ec5309af9a5a6f01ee97345d05823ea50853e07c.png)

@JammyDodger

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [July 5, 2022, 4:50am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/16 "2022-07-05T04:50:32Z")

</div>

Looking at that screenshot, it seems you’ve tweaked the parameter at the top, which will actually stop it from working. If you leave it as `:user_id` it will give you a selection box when you run it where you can type a user name. 👍

Alternatively you could ditch the parameter and add the user id you got from the json to the `WHERE p.user_id =` line.

Does that make sense?

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [July 5, 2022, 5:53am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/17 "2022-07-05T05:53:41Z")

</div>

Seems like you may already be getting help, but clicking on it brings me to `/u/deleted-posts`, which works.

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/f/1/4f1425672badbd1972cacf6651797ccf07521a6a.png)

---

<div class="post-metadata">

### Author: ![VincentAlse](https://avatars.discourse-cdn.com/v4/letter/v/7ba0ec/32.png) [@VincentAlse](https://meta.discourse.org/u/VincentAlse)
#### Post date: [July 5, 2022, 9:31am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/18 "2022-07-05T09:31:59Z")

</div>

It works now!

I thought I needed to put user\_id in the code.

Thanks a lot @JammyDodger

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [July 6, 2022, 4:57pm UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/21 "2022-07-06T16:57:26Z")

</div>

I fixed the bug you reported with this PR yesterday, which has been already merged and can be deployed if you update your Discourse instance:

[https://github.com/discourse/discourse/pull/17329](https://github.com/discourse/discourse/pull/17329)

However, we figured out that hard deleting topics could leave orphan small actions posts in the database. This second bug was fixed with:

[https://github.com/discourse/discourse/pull/17359](https://github.com/discourse/discourse/pull/17359)

I think everything should be working fine now. Please let us know if you have more problems.

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [July 30, 2022, 5:00am UTC](https://meta.discourse.org/t/permanent-deletion-bug/231576/22 "2022-07-30T05:00:46Z")

</div>

This topic was automatically closed after 3 days. New replies are no longer allowed.
