Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

inverse_of causes infinite loop with accepts_nested_attributes_for

#3761

Given two classes

class A < ActiveRecord::Base
  belongs_to :b, :inverse_of=>:a
  accepts_nested_attributes_for :b
end

class B < ActiveRecord::Base
  has_one :a, :inverse_of=>:b
end

attempting to build and save via

a=A.new
a.attributes={:b_attributes=>{}}
a.save

creates an infinite loop and gnereates stack level too deep error. Removing the inverse_of or changing the direction of the belongs_to <=> has_one relationship makes it work correctly

Reported by twalpole · January 21st, 2010 @ 02:43 AM

State: open
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Ryan Bigg
    Ryan Bigg
    • State changed from new to needs-more-info
    • Importance changed from to Low

    Please attach a patch to duplicate this issue in Rails.

    October 14th, 2010 @ 02:00 AM

  2. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:30 AM

  3. Hung Le
    Hung Le

    We ran to a similar issue using Rails 3.0 and traced it down to having "accepted_nested_attributes_for" in both the parent and its associated model(s). The problem went away when we removed the statement in the associated models.

    November 7th, 2010 @ 11:59 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from needs-more-info to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 9th, 2011 @ 12:32 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 9th, 2011 @ 12:32 AM

  6. Stephan Kaag
    Stephan Kaag
    • State changed from stale to open

    February 21st, 2011 @ 09:26 AM

  7. hemant
    hemant

    Santiago,

    I've attached a patch that demonstrates test for this problem on master branch.

    Also I could replicate the issue locally on 3.0.3 stable branch.

    February 26th, 2011 @ 06:30 PM

  8. Joey
    Joey

    I am experiencing the same issue on the 3.0.5 stable branch with Ruby 1.9.2 p180.

    March 20th, 2011 @ 02:12 AM

  9. pechorin-andrey
    pechorin-andrey

    same error on 3.0.7 with 1.8.7 mri

    April 26th, 2011 @ 03:27 PM