# 创建 Topic 时遇到 external\_id 问题

**URL:** https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689
**Category:** Development
**Tags:** rest-api
**Created:** [2022 年10 月 12 日 10:52 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689 "2022-10-12T10:52:49Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 12 日 10:52 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/1 "2022-10-12T10:52:49Z")

</div>

你好，

1. 使用“external\_id”字段创建了一个主题（通过 REST API）。
2. 我删除了该主题，我假设该主题仍会保留在数据库中，但对用户隐藏。
3. 我尝试使用相同的“external\_id”创建相同的主题，但收到“External has already been taken”的错误。

如果主题从用户的角度被删除，那么用户应该能够使用相同的数据创建新主题，但为什么不行呢？似乎没有办法重新使用相同的“external\_id”。这看起来像一个 bug。

```console
2022/10/12 12:33:32 resp: &{Status:404 Not Found StatusCode:404 Proto:HTTP/2.0 ProtoMajor:2 ProtoMinor:0 Header:map[Content-Type:[application/json; charset=utf-8] Date:[Wed, 12 Oct 2022 10:33:32 GMT] Referrer-Policy:[strict-origin-when-cross-origin] Server:[nginx] Vary:[Accept-Encoding] X-Content-Type-Options:[nosniff] X-Discourse-Route:[topics/show_by_external_id] X-Discourse-Username:[mohan43u] X-Download-Options:[noopen] X-Frame-Options:[SAMEORIGIN] X-Permitted-Cross-Domain-Policies:[none] X-Request-Id:[26b86048-937c-451c-ac0c-b23dbcd3c8ca] X-Runtime:[0.013603] X-Xss-Protection:[0]] Body:0xc000183bc0 ContentLength:-1 TransferEncoding:[] Close:false Uncompressed:true Trailer:map[] Request:0xc00030a800 TLS:0xc0000d22c0}
2022/10/12 12:33:32 req: &{Method:GET URL:https://forums.tamillinuxcommunity.org/t/external_id/7N69MKNwQAs.json Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Api-Key:[] Api-Username:[mohan43u]] Body:<nil> GetBody:<nil> ContentLength:0 TransferEncoding:[] Close:false Host:forums.tamillinuxcommunity.org Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr: RequestURI: TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc0000260b8}
2022/10/12 12:33:32 {"errors":["The requested URL or resource could not be found."],"error_type":"not_found"}
2022/10/12 12:33:32 uploading https://www.youtube.com/watch?v=7N69MKNwQAs
2022/10/12 12:33:32 {"title":"[Youtube] ஆண்ட்ராய்டுக்கான கட்டற்ற மென்பொருள் | FOSS for Android | F-Droid | Tamil","raw":"https://www.youtube.com/watch?v=7N69MKNwQAs\nஇந்த காணொளியில் F-Droid எவ்வாறு பயன்படுத்துவது? அதன் பயன் என்ன ? - என்பதை காண்போம்.\n\nகாணொளி வழங்கியவர்: \nமணிமாறன், விழுப்புரம் கட்டற்ற மென்பொருள் குழுமம்\n\nF-Droid: http://fdroid.org/\n\n#fdroid #fossforandroid #tamil #android #vglug","category":3,"external_id":"7N69MKNwQAs"}

2022/10/12 12:33:33 failed to create Topic: https://www.youtube.com/watch?v=7N69MKNwQAs
2022/10/12 12:33:33 err: <nil>
2022/10/12 12:33:33 resp: &{Status:422 Unprocessable Entity StatusCode:422 Proto:HTTP/2.0 ProtoMajor:2 ProtoMinor:0 Header:map[Cache-Control:[no-cache, no-store] Content-Type:[application/json; charset=utf-8] Date:[Wed, 12 Oct 2022 10:33:33 GMT] Referrer-Policy:[strict-origin-when-cross-origin] Server:[nginx] X-Content-Type-Options:[nosniff] X-Discourse-Route:[posts/create] X-Discourse-Username:[mohan43u] X-Download-Options:[noopen] X-Frame-Options:[SAMEORIGIN] X-Permitted-Cross-Domain-Policies:[none] X-Request-Id:[217f7585-269a-48b3-ac5e-215e02e76bdb] X-Runtime:[0.060606] X-Xss-Protection:[0]] Body:{cs:0xc00032c180} ContentLength:-1 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0xc000352100 TLS:0xc0000d22c0}
2022/10/12 12:33:33 req: &{Method:POST URL:https://forums.tamillinuxcommunity.org/posts.json Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Api-Key:[] Api-Username:[mohan43u] Content-Type:[application/json]] Body:0xc0005b0228 GetBody:0x6b0e40 ContentLength:733 TransferEncoding:[] Close:false Host:forums.tamillinuxcommunity.org Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr: RequestURI: TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc0000260b8}
2022/10/12 12:33:33 {"action":"create_post","errors":["Title has already been used","External has already been taken"]}

```

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 12 日 21:00 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/2 "2022-10-12T21:00:12Z")

</div>

> [@Mohan43u](#):
>
> 似乎没有办法使用相同的“external\_id”。看起来像个bug。

如果第一个主题被取消删除，会发生什么？

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 12 日 21:29 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/3 "2022-10-12T21:29:54Z")

</div>

无法取消删除该主题，我没有看到任何图标/按钮可以取消删除。

---

<div class="post-metadata">

### Author: ![maiki](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/maiki/32/233950_2.png) [@maiki](https://meta.discourse.org/u/maiki)
#### Post date: [2022 年10 月 12 日 21:35 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/4 "2022-10-12T21:35:33Z")

</div>

你好 Mohan。 👋

我认为 @RGJ 所指的是：这不是一个 bug，因为 Discourse 默认使用“软删除”方法。`external_id` 将在此上下文中被使用，这是设计使然。 👍

---

<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: [2022 年10 月 13 日 05:23 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/5 "2022-10-13T05:23:52Z")

</div>

未删除帖子的图标是这个：

 ![un-delete first post](https://global.discourse-cdn.com/meta/original/4X/2/6/f/26fdf074029b0d52a188e64502f16b348451ba02.jpeg)

在主题扳手菜单中也有此选项：

 ![un-delete topic](https://global.discourse-cdn.com/meta/original/4X/0/1/7/017b93721dd3595e6ed12a4bf408a21abc3b54d9.jpeg)

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 13 日 06:02 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/6 "2022-10-13T06:02:34Z")

</div>

没有这样的东西

 ![Screenshot from 2022-10-13 07-57-11](https://global.discourse-cdn.com/meta/original/4X/e/4/9/e4949edafe8ea70a2887f5e6d39278810ffc33a9.png)

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 13 日 06:05 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/7 "2022-10-13T06:05:20Z")

</div>

> [@Mohan43u](#):
>
> 根本没有这样的东西

重点是这样的主题可以被取消删除，在这种情况下，将有两个具有相同外部 ID 的主题。externalID 应该在所有主题（包括已删除的主题）中都是唯一的。正如 @maiki 所说，这是设计使然。

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 13 日 06:12 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/8 "2022-10-13T06:12:34Z")

</div>

> [@RGJ](#):
>
> 该主题可以被取消删除

可以取消删除？怎么做？我也想取消删除那个主题，这样我的问题就能解决了。但是没有办法取消删除那个主题。

要么 discourse 应该允许使用已删除主题上使用的 external\_id，要么它应该有某种方法可以使用该 external\_id 来取消删除已删除的主题。我在这两种情况中都看不到任何一种。

所以这显然是一个 bug。

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 13 日 06:39 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/9 "2022-10-13T06:39:30Z")

</div>

上面的帖子清楚地表明，主题是可以恢复的。你似乎无法恢复这个特定主题，并不一定意味着这是bug，可能是权限或设置的问题。

你是论坛的管理员吗？

顺便说一句，请不要再将其归类为 #contribute:bug。

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 13 日 08:46 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/10 "2022-10-13T08:46:32Z")

</div>

![Screenshot from 2022-10-13 10-44-34](https://global.discourse-cdn.com/meta/original/4X/0/5/d/05dc4ec373f894d3d9d88db850ab7e211d868d3f.png)

我应该将其归类为错误吗？

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 13 日 11:10 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/11 "2022-10-13T11:10:53Z")

</div>

> [@Mohan43u](#):
>
> 我应该将此归类为错误吗？

不，你不应该。

请使用安全模式，看看是否可以执行此操作。如果不能，请详细告诉我们您看到的内容。屏幕截图将有所帮助。

> **[2022-10-13\_13-10-11](https://app.screencast.com/IeSq9o2mBfbnn)**
>
> World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 13 日 16:46 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/12 "2022-10-13T16:46:37Z")

</div>

请告诉我我是否尝试错了

---

<div class="post-metadata">

### Author: ![maiki](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/maiki/32/233950_2.png) [@maiki](https://meta.discourse.org/u/maiki)
#### Post date: [2022 年10 月 13 日 16:56 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/13 "2022-10-13T16:56:58Z")

</div>

“恢复”按钮位于“已删除”主题中。因此，您需要查看它并从那里恢复它。

您无法从用户删除帖子列表中访问相应的菜单。您必须转到主题本身才能在菜单中看到该选项：

 ![Screenshot 2022-10-13 at 09-53-39 A delete message example - Sandbox Discourse Kit](https://global.discourse-cdn.com/meta/original/4X/f/6/6/f66e9fc001077712fb06d209f9e1f77b9b378482.png)

* * *

@Mohan43u，这是否回答了您关于 `external_id` 用途的原始问题？🙂

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 13 日 17:50 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/14 "2022-10-13T17:50:16Z")

</div>

> [@maiki](#):
>
> You have to go to the topic itself to see the option in the menu:

是的，但 @Mohan43u 的观点是正确的，从“已删除帖子”列表中无法找到该选项。那么如何才能进入该主题呢？

另外，[?status=deleted](https://meta.discourse.org/t/how-to-find-deleted-posts/134424/8) 似乎不再起作用了？

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 13 日 18:44 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/15 "2022-10-13T18:44:41Z")

</div>

除了我的个人资料页面外，没有办法访问那个已删除的主题。它根本无法从类别中访问。

---

<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: [2022 年10 月 13 日 19:15 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/16 "2022-10-13T19:15:21Z")

</div>

> [@RGJ](#):
>
> 另外，[?status=deleted](https://meta.discourse.org/t/how-to-find-deleted-posts/134424/8) 似乎也不再起作用了？

`/latest?status=deleted` 在我的测试站点上对我来说是有效的？

* * *

> [@Mohan43u](#):
>
> 如果我尝试的方式不对，请告诉我

啊哈，我现在明白了。视频确实有帮助。🙂 是的，该主题标题目前不会显示在已删除主题的该视图中。这之前已经被[提出过](https://meta.discourse.org/t/topic-titles-missing-from-deleted-posts-page-when-op-is-deleted/233350)，但可能值得再看看。👍

您能否尝试 `[YourSite]/latest?status=deleted` 并查看是否可以从那里的主题列表中访问该主题？

现在我找到了另一个主题，还有一个技巧可以通过您的工作人员日志导航到已删除的主题，如果这对您有帮助的话：

> [@MarkDoerr](#):
>
> 如果需要，仍然可以通过日志访问已删除帖子的内容：
> 
> ![2022-07-18_deleted_posts_logs](https://global.discourse-cdn.com/meta/original/4X/e/8/0/e80665e24e82235bc5c482e69c4162eea9ef1f26.png)

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 13 日 19:41 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/17 "2022-10-13T19:41:43Z")

</div>

> [@JammyDodger](#):
>
> `/latest?status=deleted` 在我的测试站点上对我来说是有效的？

完全干净的论坛，截至今天早上测试通过。当我取消删除主题时，它确实会再次出现在最新列表中。

> **[2022-10-13\_21-38-43](https://app.screencast.com/bAxip41TIbVaS)**
>
> World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

> [@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: [2022 年10 月 13 日 19:44 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/18 "2022-10-13T19:44:52Z")

</div>

我认为它被欢迎主题横幅的号召性用语 (CTA) 隐藏了。您能否尝试在控制台中隐藏它，看看主题是否在它后面？（或者编辑欢迎主题以关闭横幅 🙂）

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2022 年10 月 13 日 19:49 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/19 "2022-10-13T19:49:46Z")

</div>

你说得对！

这既很精彩（你的回复），又非常令人难过（原因）。

所以现在我们有理由将其重新归类到 #Contribute > UX 了……

---

<div class="post-metadata">

### Author: ![Mohan43u](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mohan43u/32/242076_2.png) [@Mohan43u](https://meta.discourse.org/u/Mohan43u)
#### Post date: [2022 年10 月 13 日 19:50 UTC](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689/20 "2022-10-13T19:50:54Z")

</div>

> [@JammyDodger](#):
>
> 您能否尝试访问 `[YourSite]/latest?status=deleted` 并查看是否可以从那里的主题列表中访问该主题？

非常感谢，我已成功恢复该主题，我的 rest-api 客户端也运行正常。

[Next page](https://meta.discourse.org/t/problem-with-creating-topic-with-external-id/241689.md?page=2)
