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.

NoMethodError in AssociationProxy#method_missing isn't helpful

#1515

Calling a method on an association proxy that doesn't exist on the target results in a blank and unhelpful NoMethodError. Attached patch makes it more descriptive for faster debugging.

I'm clicking Josh in the responsibility list because he was so dedicated to his responsibilities when we were at talks at Rubyconf that he coded straight through the sessions!

Reported by mike · December 4th, 2008 @ 06:57 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. Repository
    Repository
    • State changed from new to resolved

    (from [566a3dce6753eb71554d54e8883204e4868aa393]) Make NoMethodError message more descriptive when an undefined message has been sent to an association [#1515 NoMethodError in AssociationProxy#method_missing isn't helpful state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    December 4th, 2008 @ 07:31 PM

  2. Murat Demirten
    Murat Demirten

    Raising NoMethodError directly in AssociationProxy's method_missing call is not a good idea. If the target object has its own method_missing call to implement some functionalities, it never called when it used in an association.

    December 8th, 2008 @ 08:51 PM

  3. Roman Shterenzon
    Roman Shterenzon

    Perhaps it's better just to call the superclass?

    
    @@ -206,7 +209,7 @@ module ActiveRecord
             # Forwards any missing method call to the \target.
             def method_missing(method, *args)
               if load_target
    -            raise NoMethodError unless @target.respond_to?(method)
    +            super unless @target.respond_to?(method)
    

    December 25th, 2008 @ 08:55 PM

  4. Steven Soroka
    Steven Soroka

    I don't think this was resolved correctly. association proxies should pass the method call on to the target so that the target can deal with it in its own method_missing, otherwise you're crippling a lot of meta-programming on AR objects

    February 3rd, 2009 @ 08:36 PM

  5. Steven Soroka
    Steven Soroka

    Perhaps the target could be sent the method inside a begin..rescue block that catches a NoMethodError and gives a more descriptive error, that way the AR object still has a chance to respond.

    February 3rd, 2009 @ 08:38 PM

  6. Steven Soroka