kipcole9 / money_sql

Money functions for the serialization of a money data type in Elixir
Other
28 stars 18 forks source link

Cast function used to return error when currency is nil #24

Closed frahugo closed 2 years ago

frahugo commented 2 years ago

Upgraded to version 1.6 and a condition is not handled in the money_sql code:

iex(1) > Money.Ecto.Composite.Type.cast(%{amount: "10", currency: nil})  
** (CondClauseError) no cond clause evaluated to a truthy value
    (digital_token 0.4.0) lib/digital_token.ex:142: DigitalToken.validate_token/1
    (ex_money 5.12.0) lib/money.ex:2280: Money.do_validate_currency/2
    (ex_money 5.12.0) lib/money.ex:211: Money.new/3
    (ex_money_sql 1.6.0) lib/money/ecto/money_ecto_composite_type.ex:96: Money.Ecto.Composite.Type.cast/2

Prior to 1.6, it was returning:

iex(1) > Money.Ecto.Composite.Type.cast(%{amount: "10", currency: nil})
{:error, [message: "The currency nil is invalid"]}
kipcole9 commented 2 years ago

Thanks for the report and apolgies for the regression. As of commit 070b4c I believe the issue is fixed.

I have published ex_money_sql version 1.7.1 with the fix.

Thanks again for the report.

frahugo commented 2 years ago

Thanks for the fix!