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.

DateTime#parse exceptions not escalated in ActiveRecord while setting attributes

#6565

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
...

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

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

No comments yet.