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.

Fail to force_reload polymorphic associations

#4873

When using the instance.association(true) syntax; where the association is polymorphic, the call will fail with a NameError: uninitialized constant error.

Expected behaviour is the loading of the association repeating the query.

I added a patch to the test proving the bug

Reported by Bertg · June 16th, 2010 @ 03:34 PM

State: stale
Milestone: none
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. Bertg
    Bertg

    Current test is not valid, working on a valid one. Sorry guys/girls.

    June 16th, 2010 @ 03:57 PM

  2. Bertg
    Bertg
    • Tag changed from rails 3.0.0.beta4, associations, belongs_to, polymorphic, testcase to rails 3.0.0.beta4, associations, belongs_to, cache, polymorphic, testcase, uncached

    Created a working testcase (test.diff).
    This test proves that polymorphic associations fail to force_load.

    assert_nothing_raised { sponsor.sponsorable(true) }

    fails

    I also added a suggestion fix, which solves the NameError.
    However, the query is not repeated and thus a following test fails.

    assert_queries(1) { assert_not_nil sponsor.sponsorable(true) }

    fails

    The solution I propose is to move the uncached method to the reflection and let it handle the uncaching.
    An other solution could be that reflections on polymorphic associations return a value when klass is called.

    June 16th, 2010 @ 04:38 PM

  3. Bertg
    Bertg
    • Tag changed from rails 3.0.0.beta4, associations, belongs_to, cache, polymorphic, testcase, uncached to rails 2.3.8, rails 3.0.0.beta4, associations, belongs_to, cache, polymorphic, testcase, uncached

    June 16th, 2010 @ 04:41 PM

  4. Bertg
    Bertg
    • Tag changed from rails 2.3.8, rails 3.0.0.beta4, associations, belongs_to, cache, polymorphic, testcase, uncached to rails 2.3.8, rails 3.0.0.beta4, associations, belongs_to, bug, cache, patch, polymorphic, regression, testcase, uncached

    June 17th, 2010 @ 08:47 AM

  5. DHH
    DHH
    • Assigned user set to Pratik

    June 17th, 2010 @ 03:56 PM

  6. Bertg
    Bertg
    • Importance changed from to Low

    Is there a way I can help resolve this problem?

    I can build a fix, but i just need to know "how" to design it. Currently the problem lays in "reflection.klass" not always returning a class.

    Either the solution would not use "reflection.klass" but directly "reflection.uncached" (as suggested) or polymorphic associations should return a "polymorphic" class.

    Priority should also be higher than "Low" as this is a regression bug.

    June 28th, 2010 @ 09:49 AM

  7. Staszek
    Staszek

    I have also has this problem.
    My suggestion is to change 'klass' or 'class_name' method from AssociationReflection. I think there is the problem. Changing whole uncached method is too wide solution.

    Problem exists in rails >2.3.5 version

    December 27th, 2010 @ 06:39 PM

  8. rails
    rails
    • Tag changed from rails 2.3.8, rails 3.0.0.beta4, associations, belongs_to, bug, cache, patch, polymorphic, regression, testcase, uncached to rails 238, rails 300beta4, associations, belongs_to, bug, cache, patch, polymorphic, regression, testcase, uncached
    • State changed from new 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.

    March 28th, 2011 @ 01:00 AM

  9. rails
    rails
    • State changed from open to stale

    March 28th, 2011 @ 01:00 AM