How to restore a lost post (that was not yet published)?

If the content of the Discourse editor gets deleted unintentionally, how can I get the post draft back that was saved before? Because, the editor is saving post drafts regularly, and confirms this by saying “saved” below a post.

I just had a look into the database, but no luck. The only drafts of you that exist in there are these (either created too early or too late):

SELECT id, user_id, created_at, updated_at 
FROM drafts 
WHERE user_id = <redacted>;

  id  | user_id |         created_at         |         updated_at         
------+---------+----------------------------+----------------------------
 1895 |    3757 | 2017-08-16 10:45:21.63929  | 2017-08-16 10:45:21.63929
 3201 |    3757 | 2017-09-05 07:38:34.899062 | 2017-09-05 07:38:34.899062
 5297 |    3757 | 2017-09-24 10:30:54.010208 | 2017-09-24 10:30:54.010208
 3489 |    3757 | 2017-09-06 13:07:25.398581 | 2017-09-06 13:07:25.398581
 6213 |    3757 | 2017-10-05 10:01:20.067865 | 2017-10-05 10:01:20.067865
 2726 |    3757 | 2017-08-29 15:04:42.981928 | 2017-08-29 15:04:42.981928
(6 rows)

Drafts get erased when publishing the post eventually (which you did?). But even if we had a draft, we’d be out of luck here. Drafts get overwritten when a new revision is saved (which happens every time the “saving …” and then “saved” message appears below the editor). I just tested that. So in your case, the draft would only contain the quote instead of your text :frowning:

Can you reproduce that behavior of “quoting something erased my text”? If so, tell me how, and I’ll report it as a bug to Discourse. I could only reproduce it when selecting all my written text before doing the quoting (and in that case, even Ctrl+Z would not get my text back, which is another bug I’ll have to report …).

yeah so i was writing a looong ass text one day quoting something within the original text…then next day I quoted an other line from a response from within the post…then zouuup…

Hmm I’d like to figure out how that happened, so we can report it and spare other users your fate of losing work … . So far all my tests did not make me lose my texts though. Except for the case when I select all my text in the editor before doing the quote action. Then yes, all my text got replaced with the quote, and “Undo” / Ctrl+Z did not help to get it back.

Could that be? I mean, I’ll report this case anyway, but if yours was different I’d report that too. But for that, we need to be able to reproduce the error. So if you do again what you did (with a few lines of dummy text of course :slight_smile:), can you again produce the effect of “losing all the text”?

I do not remember exactlt how this happened or what triggered it.

So there is no way to get back an earlier version of a post draft?

Unfortunately not. I had a good look at the database structure for you to understand how it works. Tried myself to create a draft, saw where it lands, changed the draft, looked again. The old version of the draft simply gets overwritten in that case.

That behavior also makes some sense, because the drafts mechanism is meant to protect against “network error when posting it” and “browser crashed when writing it” conditions only. For the other ones, Ctrl+Z is meant to get your text back (but with that one they have admittedly some issues in the Discourse editor, one of which I found and will report to them).

So I fear you have to write it again. More often than not, the second version becomes twice as good :slight_smile: