Been dealing with at truly weird bug. I just upgraded to Rails 3 and my rake tasks are failing with:
wrong number of arguments (0 for 1)
With no line numbers, no help, no nothing even if I run “rake jobs:work –trace”.
After much agony, I narrowed the issue down to the :valid? method on my ActiveRecord objects. The actual Rails code, not my code. The interwebs seemed to suggest that there could be some issue with using deprecated validation apis (overwriting validate, for example) but I wasn’t doing that.
I eventually debugged into ActiveRecord, and discovered the problem. Check this out:
def valid?(context = nil)
context ||= (new_record? ? :create : :update)
output = super(context)
errors.empty? && output
In there we call deprecated_callback_method(:validate), but deprecated_callback_method will just execute whatever symbol you give it. So it sends :validate with no parameters. But new versions of ActiveRecord::Base expect validate to come with some sort of parameters.
On what planet is that supposed to work?
Well, it turns out if I run the exact code in my rails console, it works just fine. In a Delayed::Job task, User.first.valid? raises an ArgumentError, but in the rails console it just returns true.
Seriously. What the fuck.
My hackety-hack monkeypatch is just to throw this in my environment:
Which seems like it could be potentially bad, but if the deprecated callback method is deprecated, why would I want to use it anyway? Like I said, I don’t think I’m actually using any deprecated callbacks, but who really knows.
My job queue works again. I’m moving on.