# Updating deleted post through API returns Internal Server Error

**URL:** https://meta.discourse.org/t/updating-deleted-post-through-api-returns-internal-server-error/75839
**Category:** Bug
**Created:** [December 11, 2017, 8:48pm UTC](https://meta.discourse.org/t/updating-deleted-post-through-api-returns-internal-server-error/75839 "2017-12-11T20:48:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [December 11, 2017, 8:48pm UTC](https://meta.discourse.org/t/updating-deleted-post-through-api-returns-internal-server-error/75839/1 "2017-12-11T20:48:02Z")

</div>

Attempting to update a deleted post through the API returns a `500` error. The error is `undefined method 'id' for nil:NilClass`. It’s coming from `web_hook.rb`.

The problem is that when publishing with the All Users API key the post `update` method is calling  
`post = post.with_deleted if guardian.is_staff?`. The deleted post is then being used to trigger a `DiscourseEvent`.

My reason for wanting to get a better response when a deleted post is updated is so that the [WP Discourse](https://github.com/discourse/wp-discourse) plugin can use the response to remove the Discourse metadata it has saved for a post. It’s not safe for the plugin to assume that a `500` response means that the post has been deleted.

---

<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: [December 11, 2017, 10:40pm UTC](https://meta.discourse.org/t/updating-deleted-post-through-api-returns-internal-server-error/75839/2 "2017-12-11T22:40:54Z")

</div>

Sure, you can take this and fix the bug.. it certainly seems like one.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 21, 2018, 12:32am UTC](https://meta.discourse.org/t/updating-deleted-post-through-api-returns-internal-server-error/75839/8 "2018-05-21T00:32:07Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 21, 2018, 1:02am UTC](https://meta.discourse.org/t/updating-deleted-post-through-api-returns-internal-server-error/75839/9 "2018-05-21T01:02:40Z")

</div>

Fixed per:

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