Skip to content

Commit b358271

Browse files
committed
Note that we dup the entire reflection instance
1 parent c7e847f commit b358271

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/active_model/serializer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def associations(include_directive = ActiveModelSerializers.default_include_dire
347347
return Enumerator.new {} unless object
348348

349349
Enumerator.new do |y|
350-
(@reflections ||= self.class._reflections.deep_dup).each do |key, reflection|
350+
(self.instance_reflections ||= self.class._reflections.deep_dup).each do |key, reflection|
351351
next if reflection.excluded?(self)
352352
next unless include_directive.key?(key)
353353

@@ -411,6 +411,6 @@ def associations_hash(adapter_options, options, adapter_instance)
411411

412412
protected
413413

414-
attr_accessor :instance_options, :reflections
414+
attr_accessor :instance_options, :instance_reflections
415415
end
416416
end

lib/active_model/serializer/reflection.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def include_data?(include_slice)
151151
# @yield [ActiveModel::Serializer]
152152
# @return [:nil, associated resource or resource collection]
153153
def value(serializer, include_slice)
154+
# NOTE(BF): This method isn't thread-safe because the _reflections class attribute is not thread-safe
155+
# Therefore, when we build associations from reflections, we dup the entire reflection instance.
156+
# Better solutions much appreciated!
154157
@object = serializer.object
155158
@scope = serializer.scope
156159

0 commit comments

Comments
 (0)