Updating deleted post through API returns Internal Server Error

AI-generated summary

A bug was reported by simon where updating a deleted post through the API returns a 500 error. The issue occurs when the update method is called on a deleted post using the All Users API key, causing a NilClass error. simon suggests a better response is needed to ensure the WP Discourse plugin can safely remove metadata associated with the post. codinghorror confirmed the bug and allowed sam to resolve the issue, which was fixed via a pull request on GitHub: https://github.com/discourse/discourse/pull/5520.

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 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.

7 Mi Piace

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

3 Mi Piace

Fixed per:

https://github.com/discourse/discourse/pull/5520

3 Mi Piace