I am trying to save custom fields for a post that needs review. When I approve the post, the custom fields don’t get saved.
I checked the :approved_post event and the custom fields aren’t getting set in the payload.
How to preserve custom fields for reviewable posts.
Also, I used NewPostManager, and there in the handler, the custom fields are available, but ofcourse it gets triggered before saving the data to reviewables.
Can you show us some code? Ideally the minimal amount we can use to reproduce this issue.
I’m fixing an issue with events plugin where the events data in the post_custom_field doesn’t get saved if the category is set to require approval for topics.
I reffered to the polls plugin and there it seems that the custom fields are being set on
this is the snippet from polls.
NewPostManager.add_handler(1) do |manager|
post = Post.new(raw: manager.args[:raw])
result = NewPostResult.new(:poll, false)
post.errors.full_messages.each do |message|
result.errors[:base] << message
manager.args["is_poll"] = true
on(:approved_post) do |queued_post, created_post|
In my attempt, the custom fields data is available at,
NewPostManager, but the
ReviewableQueuedPost instance in the callback of
:approved_post (which ideally should have the custom field in its payload) doesn’t have it.
NewPostManager.add_handler do |manager|
if manager.args['event'] && NewPostManager.post_needs_approval?(manager) # this condition stands true
manager.args['is_event'] = true
on(:approved_post) do |reviewable, post|
p reviewable.payload['is_event'] #data isn't available here
This is interesting because I would not expect the polls to work here either. The args passed to manager are not automatically put into the reviewable’s payload.
I suspect there’s a bug here with polls and queued posts. I suspect
validate_polls is never called after approval. @Roman_Rizzi can you look into it?
I confirm this is a bug.
is_poll is not being stored inside the payload, making the callback useless.
Here’s a PR to fix it:
I also added a new interface so we can extend the list of allowed attributes from a plugin.
Thanks a lot for this @Roman_Rizzi, @eviltrout. I spent 2 complete days figuring this out.
@Roman_Rizzi, Do you think this feature needs to be backported?
I think it should be so that people on tests-passed and release branches can also benifit. I think some if not most plugins that use `post_custom_fields’ need to handle this edge case.
@merefield. Ohh, I didn’t notice.