Category serializer modification is behaving differently in 2.4.0

After upgrading to Release v2.4.0.beta2 · discourse/discourse · GitHub, almost all of our plugins (i.e. topic list previews, events, locations, ratings etc) have been experiencing an issue with the add_to_serializer plugin.rb method.

Existing usage followed this format:

add_to_serializer(:serializer, property) { value }

This no longer works in a production environment. It still works in a development environment.

Initially, I thought it might have something to do with the way plugin enabling is handled. As add_to_serializer’s _include? method uses the enabled? state

if define_include_method
   # Don't include serialized methods if the plugin is disabled
  klass.public_send(:define_method, "include_#{attr}?") { plugin.enabled? }

However usage of the enabled_site_setting system doesn’t seem to address the issue. Moreover, enabled? seem to still default to true anyway

def enabled?
  @enabled_site_setting ? SiteSetting.get(@enabled_site_setting) : true

To fix the immediate issue we’ve changed the way our plugins are serializing data, however I’d like to get to the bottom of this if possible. Anyone have any ideas on what’s going on here?

cc @merefield, @fzngagan


This is highly unusual since we use this in polls and they are certainly not broken. The only thing I can think of is they were broken in the beta release but fixed in master? Can you try on tests-passed and see if they work?


I’ll test it further today. The usage in polls is slightly different, as the _include? method is always precluded with a third false parameter. I suspect the include? method may be the issue.

add_to_serializer(:post, :polls_votes, false)

It seems this issue is specific to modifications of the category serializers. has a single plugin installed, “test-add-to-serializer”

As you can see in the plugin.rb, a number of serializer modifications are made.

The modifications to the non-category serializers seem to be working, but the modifications to the basic_category serializer only work in development.

You won’t find the test category properties at


But you will find the other test properties at


So the issue seems to be not about the add_to_serializer method per se, but the modification of the basic_category serializer.


@joffreyjaffeux @udan11 Hey :), it looks like you guys have done some recent work to discourse-voting to address the same issue I’ve outlined above.

Do you know why it’s no longer sufficient to add properties to the basic_category_serializer?


I can confirm this is affecting tests-passed

1 Like

Dan is out, but essentially there are 3 different places we serialize categories with varying amounts of data. We will see if there is any way to eliminate the mixin here which makes this harder to reason about.


Fixed and backported to stable and beta.

Dan correctly setup the inheritance structure, it is just that we had a very very very long standing core bug.


Thanks @sam, much appreciated.


Thanks for reporting and pushing on this, it was a very very tricky one to nail down I spend some time reading rails internals to figure this out.

Be sure to check out the new test if you are curious at how we ensure this is good going forward.


Thanks a lot, @sam for fixing this quickly.

@angus. Will our plugin work without the recent changes we made due to this fix?