You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upgrading from 4.1.8 to 4.2.0 I have run into a weird edge-case for PG decimal columns without precisions defined.
It was a bug in my application code that we didn't have the precision defined.
However, if Postgres supports it, so we probably should try to too.
gem'activerecord','4.2.0'require'active_record'# # Print out what version we're runningputs"Active Record #{ActiveRecord::VERSION::STRING}"# Connect to an in-memory sqlite3 database (more on this in a moment)ActiveRecord::Base.establish_connection(:adapter=>'sqlite3',:database=>':memory:')# Create the minimal database schema necessary to reproduce the bugActiveRecord::Schema.definedocreate_table:users,:force=>truedo |t|
t.decimal:allowanceendend# Create the minimal set of models to reproduce the bugclassUser < ActiveRecord::BaseendUser.new(allowance: 22.68).allowance == 22.68.to_d# fails
In this case because the precision.to_i is zero, the float_precision is zero and we end up calling BigDecimal.new(22.68, 0) which returns #<BigDecimal:7fd859c87cb8,'0.2267999999 9999999715 7829056959 59925652E2',45(54)>
This functionality seems to have been changed in #16333
The text was updated successfully, but these errors were encountered:
Upgrading from 4.1.8 to 4.2.0 I have run into a weird edge-case for PG decimal columns without precisions defined.
It was a bug in my application code that we didn't have the precision defined.
However, if Postgres supports it, so we probably should try to too.
This seems to be due to the
cast_value
method in this file. https://github.com/rails/rails/blob/master/activerecord/lib/active_record/type/decimal.rb#L19In this case because the
precision.to_i
is zero, thefloat_precision
is zero and we end up callingBigDecimal.new(22.68, 0)
which returns#<BigDecimal:7fd859c87cb8,'0.2267999999 9999999715 7829056959 59925652E2',45(54)>
This functionality seems to have been changed in #16333
The text was updated successfully, but these errors were encountered: