Skip to content

Commit

Permalink
Merge pull request #50163 from EduardoGHdez/interval-overflow-protection
Browse files Browse the repository at this point in the history
Improve interval overflow protection
  • Loading branch information
byroot committed Dec 11, 2023
2 parents 46d98f1 + c528b34 commit f5c6aa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -33,7 +33,7 @@ def serialize(value)
when ::Numeric
# Sometimes operations on Times returns just float number of seconds so we need to handle that.
# Example: Time.current - (Time.current + 1.hour) # => -3600.000001776 (Float)
value.seconds.iso8601(precision: self.precision)
ActiveSupport::Duration.build(value).iso8601(precision: self.precision)
else
super
end
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/adapters/postgresql/datatype_test.rb
Expand Up @@ -44,6 +44,13 @@ def test_time_values
assert_equal (-21.day), @first_time.scaled_time_interval
end

def test_update_large_time_in_seconds
@first_time.scaled_time_interval = 70.years.to_f
assert @first_time.save
assert @first_time.reload
assert_equal 70.years, @first_time.scaled_time_interval
end

def test_oid_values
assert_equal 1234, @first_oid.obj_id
end
Expand Down

0 comments on commit f5c6aa3

Please sign in to comment.