Closed dhedlund closed 1 year ago
@dhedlund great catch and thank you very much for the PR. Sorry for the delay, just landed from a long flight. Will merge and publish a new version ASAP.
🥳🥳🥳🥳🥳
I agree with your opinion that it's better to raise an exception when bad data is detected. It's a goal to never represent an invalid currency and amount and your PR reflects that intent. Its not great that older versions permitted invalid data but that's not a good enough reason to perpetuate that bad data.
I've published ex_money_sql version 1.9.3 with the following changelog entry:
Inf
and NaN
. Thanks to @dhedlund for the report and PR. Closes #34.Thanks again for the PR and support, really appreciate it.
Before
:ex_money
5.12.2, it was possible to persist money values that are no longer valid. When trying to load these values with a version of:ex_money
> 5.12.2, the field gets set to a value like:I would expect loading to either fail, or for a
%Money{}
struct to still be returned that bypasses the casting performed byMoney.new/_
. This PR handles theMoney.InvalidAmountError
the same way as invalid currencies.I originally started down the path of allowing an
:invalid_amount
option to be specified as a parameter on the ecto schema field that would allow controlling what to do such as:zero
,:cast
, and:raise
. Eventually, I decided it was probably best for whoever has any bad data to see the exception raised by the load error and just fix the data in the database; making it an option means it has to be supported for a long time, and a very small number of people are likely to have these values.