Post_created, post_edited Webhooks enqueue issue

Recently, we faced an issue with the ratings plugin where stale/empty data was being passed to the webhooks. Turns out, the reason is that DiscourseEvents are being relied on for enqueing the hooks.

This causes the webhook to be enqueued before some or all of the plugins run their modifications as we don’t have any mechanism to ensure what runs before/after what. Especially, The core code would take higher priority.

I’m proposing these webhooks be enqueued after the DiscourseEvent.trigger call so that point, all plugins have run their modifications to the model.

Thoughts?

6 Likes

Maybe do a PR for the change, in principle sounds OK.

4 Likes

Me and @angus discussed this and found a very simple solution to this problem. It seems to be working fine.

Writing the on() code outside after_initialize solves the issue. I think that’s how all the plugins should do that. I think the issue was on our part.

The reason this works is, the control enters plugin.rb before the rails initializers are run and hence the on() callbacks get registered before the webhooks are enqueued.

1 Like