Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Setting an ill-formatted Time-ish String into a TimeZone aware column raises an ArgumentError #14253

wants to merge 1 commit into from

4 participants

Akira Matsuda Arthur Nogueira Neves Tom Kadwill Robin Dupret
Akira Matsuda

Giving a Date._parseable but invalid DateTime-ish String value into a TimeZone aware AR column immediately raises since 4.0.x.

This regression was caused by 41ff6a1 which stopped rescuing errors when parsing.

This patch brings back the AR3 behaviour that sets nil in such case instead of raising.
/cc @pixeltrix

Arthur Nogueira Neves

I guess this is a dup of #11867

Tom Kadwill

@amatsuda looks like this bug is being addressed in #11867. Any reason to keep it open or can we close the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -34,7 +34,7 @@ def define_method_attribute=(attr_name)
if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
method_body, line = <<-EOV, __LINE__ + 1
def #{attr_name}=(time)
- time_with_zone = time.respond_to?(:in_time_zone) ? time.in_time_zone : nil
+ time_with_zone = time.respond_to?(:in_time_zone) ? time.in_time_zone : nil rescue nil
previous_time = attribute_changed?("#{attr_name}") ? changed_attributes["#{attr_name}"] : read_attribute(:#{attr_name})
write_attribute(:#{attr_name}, time)
#{attr_name}_will_change! if previous_time != time_with_zone
9 activerecord/test/cases/attribute_methods_test.rb
@@ -668,6 +668,15 @@ def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
+ def test_setting_time_zone_aware_attribute_to_a_broken_time_ish_string_returns_nil
+ in_time_zone "Pacific Time (US & Canada)" do
+ record =
+ record.written_on = '2009-08'
+ assert_nil record.written_on
+ assert_nil record[:written_on]
+ end
+ end
def test_setting_time_zone_aware_attribute_interprets_time_zone_unaware_string_in_time_zone
time_string = 'Tue Jan 01 00:00:00 2008'
(-11..13).each do |timezone_offset|
Something went wrong with that request. Please try again.