Backport Bugfix: Stack Overflow (3-0-stable) #5044

Merged
merged 2 commits into from Apr 30, 2012

Projects

None yet

5 participants

@AntiTyping

Bugfix for #2525 belongs_to + :inverse_of + accepts_nested_attributes_for causes stack overflow on save

I run into the same issue. There is a cyclic autosave for belongs_to/has_one when using accepts_nested_attributes. It causes stack overflow.

@tenderlove
Member

Do you mind adding a test for this? Also, does it occur on the master branch?

@AntiTyping
  1. I added a test.
  2. I just verified that the issue does not occur on the master branch.
@carlosantoniodasilva

@jonleighton @tenderlove should this be applied to 3-0, could you please check? ^^

@tenderlove tenderlove commented on the diff Apr 30, 2012
activerecord/lib/active_record/autosave_association.rb
@@ -140,6 +140,23 @@ def #{type}(name, options = {})
CODE
end
+ def define_non_cyclic_method(name, reflection, &block)
+ define_method(name) do |*args|
+ result = true; @_already_called ||= {}
@tenderlove
tenderlove Apr 30, 2012 Ruby on Rails member

Does this need to be an instance variable?

@wycats wycats merged commit 51582fe into rails:3-0-stable Apr 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment