This project is archived and is in readonly mode.

#1515 ✓resolved
mike

NoMethodError in AssociationProxy#method_missing isn't helpful

Reported by mike | December 4th, 2008 @ 06:57 PM | in 2.x

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!

Comments and changes to this ticket

  • Repository

    Repository December 4th, 2008 @ 07:31 PM

    • State changed from “new” to “resolved”

    (from [566a3dce6753eb71554d54e8883204e4868aa393]) Make NoMethodError message more descriptive when an undefined message has been sent to an association [#1515 state:resolved]

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

  • Murat Demirten

    Murat Demirten December 8th, 2008 @ 08:51 PM

    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.

  • Roman Shterenzon

    Roman Shterenzon December 25th, 2008 @ 08:55 PM

    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)
    
  • Steven Soroka

    Steven Soroka February 3rd, 2009 @ 08:36 PM

    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

  • Steven Soroka

    Steven Soroka February 3rd, 2009 @ 08:38 PM

    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.

  • Steven Soroka

    Steven Soroka March 30th, 2009 @ 10:42 PM

    I have a better solution, which I've provided with a patch in #2378

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>

People watching this ticket

Referenced by

Pages