PermanentDeleteChannel fails with "failed to get a thread"

Description

A customer is seeing this error come up when they try to delete a channel using mmctl or the inbuilt cli:

```
{"level":"error","ts":1609946082.091247,"caller":"mlog/log.go:229","msg":"Unable to delete the posts by channel.","path":"/api/v4/channels/kknpcbkdafg7uchk8i34jercrw","request_id":"1i71xpj5m7fwfbrotqd7nonxww","ip_addr":"xxx","user_id":"hx9inobaef8wuruqgiwc3bbzsr","method":"DELETE","err_where":"PermanentDeleteChannel","http_code":500,"err_details":"failed to get a thread: resource: Thread id: 8phskmna5bn13k4axbamhsmnja"}
```

This is happening on 5.29.1

The issue seems to be fixed in 5.30 (https://github.com/mattermost/mattermost-server/pull/16091).

PermanentDeleteUser is also affected by the same issue:

https://community-daily.mattermost.com/core/pl/5g7hjjcmt3bj9ruhnans5pgdbo

QA Test Steps

-successfully deleted users and channels with mmctl
-no error

Activity

Show:
Eric Sethna
January 14, 2021, 4:43 AM

does this impact users transitioning to use collapsed reply threads?

Colton Shaw
January 23, 2021, 7:41 AM

I am hitting this same issue in my customer's environment using user delete [ID]. This seems related to posts that have RootID and ParentID configured. We deleted all rows associated with the UserID that had Root/Parent IDs and it resolved the delete issue.

Daniel Espino Garcia
January 27, 2021, 9:43 PM

Bug seems to be introduced by https://github.com/mattermost/mattermost-server/pull/15571/files .

Fix should work for all versions (current and any cherrypick for a dot release we might want to do on previous versions).

PR here:

Ogi Marusic
February 5, 2021, 9:22 AM

Tested and passed on v5.31.1-rc1

QA Note: added done-5.31 label, leaving open to test on v5.32

Ogi Marusic
February 12, 2021, 11:44 AM

Tested and passed on v5.32

QA Note: PR labelled. Closing.

Done

Mana

None

Assignee

Daniel Espino Garcia

QA Assignee

Ogi Marusic

Reporter

Claudio Costa

Epic Link

None

Mattermost Team

Sustained Engineering

Sprint

None

QA Testing Areas

CLI

GitHub Issue

None

Components

None

Severity

None