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.

"warning: default 'to_a' will be obsolete" from method_missing in association_proxy

#5130

Similar to #2121 "warning: default 'to_a' will be obsolete" from method_missing in association..., I get a lot of these:

.../gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:215: warning: default `to_a' will be obsolete

the culprit seems to be the method_missing system. The line of code which kicks things off is:

.../gems/ar-extensions-0.9.2/lib/ar-extensions/extensions.rb:259:in `process'
    values = [*val]

That splat is translated to :to_a for method_missing, so when association_proxy calls @target.send(method, *args, &block), the warning is thrown.

So, I'm not sure where the fix should go, but spamming my log file is certainly not the right solution.

Reported by Greg Hazel · July 16th, 2010 @ 01:27 AM

State: invalid
Milestone: none
Assigned to: Rohit Arondekar Rohit Arondekar
Importance: Low

Activity

  1. David Trasbo
    David Trasbo
    • Assigned user set to Rohit Arondekar

    What you're seeing is a warning Rails throws because of some code in an third party gem. The fix should go in that gem - there's a reason Rails throws the warning, and it's there to remind people to fix their code.

    This can be closed.

    August 1st, 2010 @ 02:20 PM

  2. Greg Hazel
    Greg Hazel

    Fix their code to say what? They are not using Object#to_a, they are using [*val].

    August 1st, 2010 @ 02:26 PM

  3. Rohit Arondekar
    Rohit Arondekar
    • Importance changed from to Low

    It certainly looks like an issue of ar-extensions. Can you try opening a ticket/issue there? :)

    August 1st, 2010 @ 02:32 PM

  4. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid

    August 1st, 2010 @ 02:32 PM

  5. Greg Hazel
    Greg Hazel

    And what should I request that they do differently? Rails is throwing a warning about to_a, what is the solution?

    August 1st, 2010 @ 02:33 PM

  6. Greg Hazel
    Greg Hazel

    FYI, it was filed 8 months ago, with no response: http://github.com/zdennis/ar-extensions/issues#issue/6

    It's not clear what other code should do here. Rails should remove the warning, or make some indication about alternatives.

    August 1st, 2010 @ 02:34 PM

  7. Rohit Arondekar
    Rohit Arondekar
    • State changed from invalid to new

    Greg, somebody provided a patch in that ticket: http://github.com/thillerson/ar-extensions/commit/fc0cab906ebc3766f... The patch is for ar-extensions. Can you try commenting on that ticket and see if the author responds?

    August 1st, 2010 @ 02:36 PM

  8. Greg Hazel
    Greg Hazel

    Well, we'll see. The developer obvious has not done anything with the extension for some time.

    The to_a function is (maybe, eventually) being obsoleted by Ruby -- I don't see why Rails needs to try to enforce that by spamming my logs.

    August 1st, 2010 @ 02:45 PM

  9. Rohit Arondekar
    Rohit Arondekar

    Can you try applying that patch manually to see if it fixes the issue?

    August 1st, 2010 @ 02:56 PM

  10. David Trasbo
    David Trasbo

    Greg,

    to_a is not obsoleted by Ruby, that's not what the warning says. As I said that warning can't just be removed because you don't want your logs spammed because of code in another gem. There's a reason this warning is thrown.

    Yes, to_a is called implicitly here, but that doesn't matter. Rails doesn't know better.

    August 1st, 2010 @ 03:14 PM

  11. Greg Hazel
    Greg Hazel

    What is the reason the warning is thrown? It is not informative to me.

    August 1st, 2010 @ 09:15 PM

  12. David Trasbo
    David Trasbo

    The warning is thrown because calling to_a on an instance of AssociationProxy will be obsolete just like the warning says. Once again: There's a perfectly good technical reason this warning is thrown, and it's there to remind people to fix there code - removing a warning doesn't fix the cause of the warning.

    Please do close this ticket.

    September 9th, 2010 @ 01:29 PM

  13. David Trasbo
  14. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid

    September 9th, 2010 @ 01:43 PM

  15. Greg Hazel
    Greg Hazel

    Can you suggest how the issue should be solved? The code which generates this error is not even using to_a, it's using the splat operator.

    September 9th, 2010 @ 10:48 PM