This project is archived and is in readonly mode.

#6565 new
Xavier Spriet

DateTime#parse exceptions not escalated in ActiveRecord while setting attributes

Reported by Xavier Spriet | March 11th, 2011 @ 08:01 PM

While updating a model with a datetime field, if the datetime string is provided in a format that DateTime#parse is not able to parse,
the field is just set to nil.

While calling DateTime#parse directly against that string, an ArgumentError: invalid date exception is thrown.

Setting through ActiveRecord:

ruby-1.9.2-p180 :001 > record = Production.where(:record_timestamp => nil).last

 => #<Production id: 175178, inverter_id: 13, created_at: "2011-03-11 17:59:16", updated_at: "2011-03-11 17:59:16", kwh_total: -1000.0, irradiance: 0.0, record_timestamp: nil, ambient_temp: nil> 


ruby-1.9.2-p180 :002 > record.record_timestamp = '09/27/2010 22:26:49'
 => "09/27/2010 22:26:49" 
ruby-1.9.2-p180 :003 > record.record_timestamp
 => nil

Using DateTime#parse:

ruby-1.9.2-p180 :004 > DateTime.parse '09/27/2010 22:26:49'
ArgumentError: invalid date
...

No comments found

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

Pages