Skip to content

Commit f5c6aa3

Browse files
authored
Merge pull request rails#50163 from EduardoGHdez/interval-overflow-protection
Improve interval overflow protection
2 parents 46d98f1 + c528b34 commit f5c6aa3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

activerecord/lib/active_record/connection_adapters/postgresql/oid/interval.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def serialize(value)
3333
when ::Numeric
3434
# Sometimes operations on Times returns just float number of seconds so we need to handle that.
3535
# Example: Time.current - (Time.current + 1.hour) # => -3600.000001776 (Float)
36-
value.seconds.iso8601(precision: self.precision)
36+
ActiveSupport::Duration.build(value).iso8601(precision: self.precision)
3737
else
3838
super
3939
end

activerecord/test/cases/adapters/postgresql/datatype_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ def test_time_values
4444
assert_equal (-21.day), @first_time.scaled_time_interval
4545
end
4646

47+
def test_update_large_time_in_seconds
48+
@first_time.scaled_time_interval = 70.years.to_f
49+
assert @first_time.save
50+
assert @first_time.reload
51+
assert_equal 70.years, @first_time.scaled_time_interval
52+
end
53+
4754
def test_oid_values
4855
assert_equal 1234, @first_oid.obj_id
4956
end

0 commit comments

Comments
 (0)