active_model_serializers
active_model_serializers copied to clipboard
Runtime modification of parent serializer attributes doesn't update child attributes
This is more of a question, since I'm not sure you want to support this use case. This is related to an issue with Discourse - https://meta.discourse.org/t/inconsistent-behaviour-in-plugins-between-development-and-production/87220
Expected behavior vs actual behavior
If you call attributes in a parent serializer after you defined a child serializer, changes to the parent will not be reflected in child attributes
class ParentSerializer < ActiveModel::Serializer
attributes :name
end
class ChildSerializer < ParentSerializer
attributes :email
end
ParentSerializer.attributes(:last_name)
Actual
ParentSerializer._attributes => {:name=>:name, :last_name=>:last_name}
ChildSerializer._attributes => {:name=>:name, :email=>:email}
Expected
ParentSerializer._attributes => {:name=>:name, :last_name=>:last_name}
ChildSerializer._attributes => {:name=>:name, :email=>:email, :last_name=>:last_name}
Steps to reproduce
I made a failing test case https://github.com/orlando/active_model_serializers/commit/91408c9ac2ed9167a8c480fdbad3b6889e2e38b9
Environment
ActiveModelSerializers Version 0.8.4: