Note that we dup the entire reflection instance

This commit is contained in:
Benjamin Fleischer 2018-11-01 14:20:20 -05:00
parent c7e847fc72
commit b358271ef5
2 changed files with 5 additions and 2 deletions

View File

@ -347,7 +347,7 @@ module ActiveModel
return Enumerator.new {} unless object return Enumerator.new {} unless object
Enumerator.new do |y| Enumerator.new do |y|
(@reflections ||= self.class._reflections.deep_dup).each do |key, reflection| (self.instance_reflections ||= self.class._reflections.deep_dup).each do |key, reflection|
next if reflection.excluded?(self) next if reflection.excluded?(self)
next unless include_directive.key?(key) next unless include_directive.key?(key)
@ -411,6 +411,6 @@ module ActiveModel
protected protected
attr_accessor :instance_options, :reflections attr_accessor :instance_options, :instance_reflections
end end
end end

View File

@ -151,6 +151,9 @@ module ActiveModel
# @yield [ActiveModel::Serializer] # @yield [ActiveModel::Serializer]
# @return [:nil, associated resource or resource collection] # @return [:nil, associated resource or resource collection]
def value(serializer, include_slice) def value(serializer, include_slice)
# NOTE(BF): This method isn't thread-safe because the _reflections class attribute is not thread-safe
# Therefore, when we build associations from reflections, we dup the entire reflection instance.
# Better solutions much appreciated!
@object = serializer.object @object = serializer.object
@scope = serializer.scope @scope = serializer.scope