This project is archived and is in readonly mode.

#4873 ✓stale
Bertg

Fail to force_reload polymorphic associations

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

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

Comments and changes to this ticket

  • Bertg

    Bertg June 16th, 2010 @ 03:57 PM

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

  • Bertg

    Bertg June 16th, 2010 @ 04:38 PM

    • 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.

  • Bertg

    Bertg June 16th, 2010 @ 04:41 PM

    • 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
  • Bertg

    Bertg June 17th, 2010 @ 08:47 AM

    • 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
  • DHH

    DHH June 17th, 2010 @ 03:56 PM

    • Assigned user set to “Pratik”
  • Bertg

    Bertg June 28th, 2010 @ 09:49 AM

    • 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.

  • Staszek

    Staszek December 27th, 2010 @ 06:39 PM

    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

  • rails

    rails March 28th, 2011 @ 01:00 AM

    • 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.

  • rails

    rails March 28th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages