diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-01-07 15:56:50 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-01-07 15:56:50 -0800 |
commit | f6b21d48ef15d4f39a530653c2ce7d0cfb458b46 (patch) | |
tree | 877090d36f381f3c5237d281e362a96c2a05bc92 /activerecord/lib/active_record/autosave_association.rb | |
parent | af2e0fec0971e1a9d76a5cd87c9324c3d92e5ec1 (diff) | |
parent | fb71fa695d214eb5aaa6f95440347e3a08f03b38 (diff) | |
download | rails-f6b21d48ef15d4f39a530653c2ce7d0cfb458b46.tar.gz rails-f6b21d48ef15d4f39a530653c2ce7d0cfb458b46.tar.bz2 rails-f6b21d48ef15d4f39a530653c2ce7d0cfb458b46.zip |
Merge pull request #16640 from mfazekas/fix_loop_in_changed_for_autosave
Fix potenital infinite recursion in changed_for_autosave?
Diffstat (limited to 'activerecord/lib/active_record/autosave_association.rb')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index fa6c5e9e8c..fcaaffb852 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -278,11 +278,18 @@ module ActiveRecord # go through nested autosave associations that are loaded in memory (without loading # any new ones), and return true if is changed for autosave def nested_records_changed_for_autosave? - self.class._reflections.values.any? do |reflection| - if reflection.options[:autosave] - association = association_instance_get(reflection.name) - association && Array.wrap(association.target).any?(&:changed_for_autosave?) + @_nested_records_changed_for_autosave_already_called ||= false + return false if @_nested_records_changed_for_autosave_already_called + begin + @_nested_records_changed_for_autosave_already_called = true + self.class._reflections.values.any? do |reflection| + if reflection.options[:autosave] + association = association_instance_get(reflection.name) + association && Array.wrap(association.target).any?(&:changed_for_autosave?) + end end + ensure + @_nested_records_changed_for_autosave_already_called = false end end |