# Can't delete user with PMs, misleading error message

**URL:** https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969
**Category:** Bug
**Created:** [May 28, 2021, 7:56pm UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969 "2021-05-28T19:56:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [May 28, 2021, 7:56pm UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969/1 "2021-05-28T19:56:26Z")

</div>

We are using SSO and when someone closes their account, we delete their Discourse account too through the API (or anonymize it, if there’s posts).

However, something seems to be amiss as we have been seeing some 403 errors while doing this. Poking a little bit, I found this to be the error message returned by the API call:

```plaintext
{
    "http_code": 403,
    "body": "{\"deleted\":false,\"message\":\"User XXX has 0 posts, so they can't be deleted.\"}"
}

```

Bit, if there’s 0 posts, it should be possible to be deleted? Looking at the info for this particular account, there’s indeed no posts:

 ![Screenshot 2021-05-28 at 19.37.30](https://global.discourse-cdn.com/meta/original/3X/3/3/33b1c025c0942f723a7f4b08d14037718e2cf42e.png)

However, there’s a private message to Discobot (tutorial).

 ![Screenshot 2021-05-28 at 19.36.29](https://global.discourse-cdn.com/meta/original/3X/2/5/2552e7eb72c6f7385060bee370b5fa17c1e9372d.png)

So, I think there’s a few things here:

1. The error message that refused the deletion of the user is counting only the public posts, but perhaps it should count private too?
2. Actually, should the private messages prevent an account from being deleted? I understand the reasoning for how removing an account complicates the narrative on a public topic, but on a private message perhaps the argument is not as solid?
3. If the answer to the previous one is still a yes (ie, private message should still prevent removing an account from being removed), should messages to Discobot count too, towards preventing an account from being removed? What I mean is, most people will go through the tutorial and send PMs to Discobot… which makes it virtually impossible to remove many accounts that never participated, just because they did the tutorial (perhaps this is true only after `delete_user_max_post_age` days, but still).

Lastly, and I’m not sure if this is related with 1., but when checking the API info for this user, it returns:  
`post_count: 0`  
`can_be_deleted: 1`  
`can_delete_all_posts: 0`

But, effectively, this user can’t be deleted. So perhaps the `can_be_deleted` logic is counting only public posts too?

---

<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: [May 28, 2021, 8:53pm UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969/2 "2021-05-28T20:53:19Z")

</div>

Good sleuthing! We should fix the error message at minimum.

`"body": "{\"deleted\":false,\"message\":\"User XXX has 0 posts, so they can't be deleted.\"}"`

It should say

`User has x post(s), so they can't be deleted.`

We should also probably hint at the situation since this has come up a fair bit

`User has x posts(s), either public posts or personal messages, so they can't be deleted`

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [June 4, 2021, 6:16am UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969/4 "2021-06-04T06:16:14Z")

</div>

> [@codinghorror](#):
>
> We should fix the error message at minimum.

It’s done. I also fixed the incorrect post count in the message.

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

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [June 5, 2021, 8:39am UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969/5 "2021-06-05T08:39:31Z")

</div>

Thank you @vinothkannans! 👍

Any chance the fact that `can_be_deleted` seems to say an account can be deleted when it can’t (due to PMs) can also be looked into? At the moment we have to try deleting the user first and then fallback to anonymize when that fails (since `can_be_deleted` can’t be trusted).

---

<div class="post-metadata">

### Author: ![griffin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/griffin/32/223139_2.png) [@griffin](https://meta.discourse.org/u/griffin)
#### Post date: [June 5, 2021, 4:13pm UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969/6 "2021-06-05T16:13:50Z")

</div>

Might the issue in the following topic be correlated in any way to the issues being discussed in this topic?

> [@Flag -\> Delete Spammer - Does not work anymore](https://meta.discourse.org/t/flag-delete-spammer-does-not-work-anymore/192748):
>
> This was working well on 2.6.x Upgraded to 2.7.1 Stable and get this error immediately when trying to use this option (flag → delete spammer) on a post or topic: There was an error deleting that user. Make sure all posts are deleted before trying to delete the user. ‘delete user max post age’ and ‘delete all posts max’ are both set to the max value of 2000000000. This option used to delete all of the user’s posts and the account itself.

---

<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: [June 8, 2021, 3:00pm UTC](https://meta.discourse.org/t/cant-delete-user-with-pms-misleading-error-message/191969/7 "2021-06-08T15:00:16Z")

</div>

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