DateTime#parse exceptions not escalated in ActiveRecord while setting attributes #922

Closed
lighthouse-import opened this Issue May 16, 2011 · 0 comments

Comments

Projects
None yet
1 participant

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6565
Created by Xavier Spriet - 2011-03-11 20:01:43 UTC

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

tomstuart pushed a commit to econsultancy/rails that referenced this issue May 17, 2011

update_attributes and update_attributes! are now wrapped in a transac…
…tion

[#922 state:resovled]

Signed-off-by: José Valim <jose.valim@gmail.com>

jake3030 pushed a commit to jake3030/rails that referenced this issue Jun 28, 2011

Wrap calls to update_attributes in a transaction.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#922 state:committed]

jake3030 pushed a commit to jake3030/rails that referenced this issue Jun 28, 2011

Revert "Wrap calls to update_attributes in a transaction."
This caused failures on sqlite, sqlite3 and postgresql

This reverts commit fc09ebc.
[#922 state:reopened]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment