# Parent message doesn't exist

**URL:** https://meta.discourse.org/t/parent-message-doesnt-exist/141746
**Category:** Migration
**Created:** [February 16, 2020, 3:59pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746 "2020-02-16T15:59:55Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [February 16, 2020, 3:59pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/1 "2020-02-16T15:59:55Z")

</div>

On import of mbxs I am getting an error that the parent message doesn’t exist even though it does seem to be in the database, index.db.

Here’s the error:

> Parent message 9205270657.AB03850@ben.dciem.dnd.ca doesn’t exist. Skipping 9206031720.AA22567@ben.dciem.dnd.ca: A CALL FOR HELP

and here’s the db entry:

![Annotation 2020-02-16 155700](https://global.discourse-cdn.com/meta/optimized/3X/3/c/3c3d13443532f1d7880bd618653c11df4a351d07_2_690x19.png)

Any suggestion why this is failing?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [February 16, 2020, 10:33pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/2 "2020-02-16T22:33:32Z")

</div>

Maybe the sort order is wrong because your are grouping emails by subject? Might be worth investigating. Messages are only sorted by `Subject` and the order of emails within the mbox file.

> <https://github.com/discourse/discourse/blob/3b062f79fccd99ebbcf92951cd3e205d574a06d6/script/import_scripts/mbox/support/database.rb#L123-L126>

Are you really sure you need to group emails by subject? Judging by your screenshot it looks like the emails have correct `Message-ID` as well as `In-Reply-To` and `References` headers.

---

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [February 17, 2020, 10:41am UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/3 "2020-02-17T10:41:02Z")

</div>

> [@gerhard](#):
>
> Maybe the sort order is wrong because your are grouping emails by subject? Might be worth investigating. Messages are only sorted by `Subject` and the order of emails within the mbox file.

Thanks. Looking at the email\_order table they look like they are in the correct order:

| msg\_id | rowid |
| --- | --- |
| 9205270657.AB03850@ben.dciem.dnd.ca | 874 |
| 9206031720.AA22567@ben.dciem.dnd.ca | 875 |

Could there be something else that is failing to import these parent message?

> [@gerhard](#):
>
> Are you really sure you need to group emails by subject? Judging by your screenshot it looks like the emails have correct `Message-ID` as well as `In-Reply-To` and `References` headers.

When I did the first import it looked like there was no grouping at all. I think the problem being that the replies are to the mailing list rather than the originator. Also, some messages don’t have those fields at all, as the archive was put together manually over 28 years in rather haphazard with different versions of Eudora.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [February 17, 2020, 11:07am UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/4 "2020-02-17T11:07:42Z")

</div>

Maybe it fails to import the parent message? Was there an error? It’s hard to tell why it doesn’t find the message. I’m sorry, but I guess you’ll need to debug this yourself by modifying the Ruby code of the import script.

---

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [February 17, 2020, 2:31pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/5 "2020-02-17T14:31:04Z")

</div>

No, I don’t believe there was an error.

> [@gerhard](#):
>
> I’m sorry, but I guess you’ll need to debug this yourself by modifying the Ruby code of the import script.

Ok, though I’m not familiar with Ruby or the import script, but I may be able to have a go.

Can you let me know which scripts to look at, and where they are? Does “debug” mean add print statements or is there more sophisticated functionality?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [February 17, 2020, 2:48pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/6 "2020-02-17T14:48:27Z")

</div>

[https://github.com/discourse/discourse/tree/master/script/import\_scripts/mbox](https://github.com/discourse/discourse/tree/master/script/import_scripts/mbox)

---

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [February 17, 2020, 9:38pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/7 "2020-02-17T21:38:32Z")

</div>

Well, I added a couple of print debugs to map\_first\_post

```
def map_first_post(row)
  puts "Mapping parent #{row['msg_id']} #{row['subject'][0..40]}"
  mapped = map_post(row)
  mapped[:category] = category_id_from_imported_category_id(row['category'])
  mapped[:title] = row['subject'].strip[0...255]
  mapped
  puts "Mapped message #{row['msg_id']} #{row['subject'][0..40]}"
end  

def map_reply(row)
  parent = @lookup.topic_lookup_from_imported_post_id(row['in_reply_to'])
  if parent.blank?
    puts "Parent message #{row['in_reply_to']} doesn't exist. Skipping #{row['msg_id']}: #{row['subject'][0..40]}"
    return nil
  end

  mapped = map_post(row)
  mapped[:topic_id] = parent[:topic_id]
  mapped
end

```

These print ok and suggest the parent is mapped (imported?)

873 / 65936 ( 1.3%) [3895 items/min]  
Mapping parent 9205270657.AB03850@ben.dciem.dnd.ca A CALL FOR HELP  
Mapped message 9205270657.AB03850@ben.dciem.dnd.ca A CALL FOR HELP  
874 / 65936 ( 1.3%) [3900 items/min]  
Parent message 9205270657.AB03850@ben.dciem.dnd.ca doesn’t exist. Skipping 9206031720.AA22567@ben.dciem.dnd.ca: A CALL FOR HELP

So, don’t see why the parent is blank in map\_reply. The only thing I note is that the numbers (873/874) are one less than rowid above.

But I don’t think I can go much further as I don’t know what @lookup.topic\_lookup\_from\_imported\_post\_id is doing and it is very laborious to edit with vi and rerun the import, with each cycle taking around 30 minutes.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 17, 2020, 10:40pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/8 "2020-02-17T22:40:27Z")

</div>

> [@ruperty](#):
>
> But I don’t think I can go much further as I don’t know what @lookup.topic\_lookup\_from\_imported\_post\_id is doing

It’s in `base.rb` in the same directory. And it’s doing exactly what the name of the function suggests, it’s looking for the topic\_id by finding the import\_id (which I assume is the message ID in this case} in a topic custom field (or maybe a post custom field?).

> [@ruperty](#):
>
> it is very laborious to edit with vi and rerun the import, with each cycle taking around 30 minutes.

That’s better than the ones that take a week. 😉 (Sometimes you can do stuff to have the import script import only the stuff you’re trying to debug; figuring out how to do so is left as an exercise to the reader.)

You can try looking at the database and see if the parent message is getting imported and if it has a `import_id` topic/post custom field.

---

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [February 18, 2020, 12:54pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/9 "2020-02-18T12:54:14Z")

</div>

> [@pfaffman](#):
>
> And it’s doing exactly what the name of the function suggests, it’s looking for the topic\_id by finding the import\_id (which I assume is the message ID in this case} in a topic custom field (or maybe a post custom field?).

Looking where? Is topic\_id the subject?

> [@pfaffman](#):
>
> You can try looking at the database and see if the parent message is getting imported and if it has a `import_id` topic/post custom field.

By ‘database’ do you mean index.db? By ‘imported’ do you mean entered in to the email table of index.db? Yes, it is there. But no column called ‘import\_id’.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 18, 2020, 1:40pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/10 "2020-02-18T13:40:29Z")

</div>

By database I mean the discourse database. The import id is in the topic\_custom\_field and post\_custom\_field tables.

---

<div class="post-metadata">

### Author: ![ruperty](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ruperty/32/164033_2.png) [@ruperty](https://meta.discourse.org/u/ruperty)
#### Post date: [February 19, 2020, 8:55pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/11 "2020-02-19T20:55:30Z")

</div>

Aha!

I imported the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin and had a look at the discourse database. I found that the import\_id for the parent message was present in the topic\_custom\_field and post\_custom\_field tables. Also, the message did exist.

But, it had been deleted. So, I guess, I was getting the error “parent message does not exist” because the import was looking in the discourse database rather than in index.db. It would’ve been good to get an error message saying the post had been deleted.

Anyway, I think this happened as, during an early test, I had deleted the first(small) batch of imported posts. I thought I had restored to before that point, but clearly not.

The good thing is that this is only applicable to my test server and I shouldn’t have the problem on the import on the live server.

Thanks for the pointers.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 19, 2020, 8:58pm UTC](https://meta.discourse.org/t/parent-message-doesnt-exist/141746/12 "2020-02-19T20:58:41Z")

</div>

> [@ruperty](#):
>
> But, it had been deleted.

Why? By whom?

> [@ruperty](#):
>
> It would’ve been good to get an error message saying the post had been deleted.

This isn’t something that happens in an import.

> [@ruperty](#):
>
> Anyway, I think this happened as, during an early test, I had deleted the first(small) batch of imported posts. I thought I had restored to before that point, but clearly not.

Sounds right. And deleting posts doesn’t delete them, but **marks them as deleted**.
