Bug of the Day: nil.include error with create_time_zone_conversion_attribute

This was an ‘orrible bug. Tired and midway through writing up a Ruby on Rails tutorial on setting up emailing with AR Mailer and a little postfix configuration I wasn’t exactly in the mood for a bizzarely cryptic issue to waste my time. Enter the mysterious create_time_zone_conversion_attribute? method in all it’s glory. Basically you will get this error if you set …

config.cache_classes = false

… wherever it is set in your environment files (in my case config/development.rb) but the error goes away if you change it to …

config.cache_classes = true

… bloody daft! Here is the bug on lighthouse. Arrgh!!!!

Anyway here is the full stack trace which may help someone googling to pick up this page

NoMethodError in UsersController#create

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?

/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:71:in `each’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:350:in `respond_to?’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2587:in `attributes=’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in `each’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in `attributes=’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2283:in `initialize’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:691:in `new’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:691:in `create’
vendor/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:92:in `perform_delivery_activerecord’
vendor/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:91:in `each’
vendor/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:91:in `perform_delivery_activerecord’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/base.rb:526:in `__send__’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/base.rb:526:in `deliver!’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/base.rb:392:in `method_missing’
app/controllers/users_controller.rb:47:in `create’
app/controllers/users_controller.rb:45:in `create’

Happy hackin’

16 Responses to “Bug of the Day: nil.include error with create_time_zone_conversion_attribute”

  1. Ed Spencer says:

    I had the same bug but needed a different solution. I was actually downgrading off edge to 2.2.0 so maybe my situation was different. This did the trick for me: http://www.railsformers.com/article/activerecord-timezone-settings-bug

  2. Frank says:

    Thanks a lot for this post – that is a horrible and very opaque bug and I don’t think I would have solved that without your help!! Your solution works perfectly although of course that also means that I now have to remember to restart the server after every change to the code.

  3. I ran into this bug several times. Most recently for a route (with a path_prefix) that should have worked fine, but threw this error. Your solution fixed the problem, but as Frank said, requires constant server restarts in development mode :-P

  4. Stefan Enberg says:

    Thanks for your work-around advice.

  5. [...] e mais de uma vez. Depois de muito procurar, acabamos encontrando referências para a solução aqui, aqui e, finalmente, aqui. O  último link descreve perfeitamente o nosso problema. A solução, [...]

  6. Stef says:

    This is fixed by changing this line in your environment.rb (or anywhere else you have it):

    config.time_zone = ‘UTC’

    to:

    config.active_record.default_timezone = :utc

    (but it then gives me a Stack Level Too Deep, but I guess that’s my problem…)

  7. Mike says:

    Thanks!

    I have been banging my head against this for hours. Stef, the time zone configuration fixed the problem for me. Thanks for posting this and for posting the error output so it was easily searchable!

  8. Pasta says:

    Thank’s a lot!

  9. KendallB says:

    I downgraded to 2.3.2 from 2.3.3, and it solved the problem for me.

  10. ceilingfish says:

    I toast your bloggerisation of this problem!

  11. th3james says:

    Thanks for blogging this, thanks to your post I fixed this quickly, I’m sure this coulda cost me hours!

  12. Vivek Rajagopalan says:

    I cant thank you enough for this. This was a really nasty one.

    Like KendallB – I too was on the verge of downgrading from 2.3.3.

  13. Thomas says:

    Thank you so much!

  14. Thanks both (the original poster and Stef) for the solution.

    I was headbanging since two hours ago! :-)

  15. Brad says:

    oh man, I had no idea why my tests were all of a sudden failing. I was using the console in test mode and didn’t want to have to restart every time i made a change. Thanks SOO much! I spent 2 hours of messing around before i decided to google this

  16. Ben says:

    Thanks Stef! Your solution fixed it for me.

Leave a Reply