kipcole9 / money_sql

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

Not compatible with Decimal 2.0 #8

Closed doughsay closed 3 years ago

doughsay commented 3 years ago

Hi there,

This library relies on Decimal.parse/1, which had a breaking change with the 2.0 release. Decimal is brought in as a transitive dependency from Money, which allows 2.0.0. This causes casting to crash if a project is updated to Decimal 2.0.

coladarci commented 3 years ago

For context @kipcole9 this is what the error looks like:

** (WithClauseError) no with clause matching: {#Decimal<0.32>, ""}
    (ex_money_sql 1.3.0) lib/money/ecto/money_ecto_composite_type.ex:62: Money.Ecto.Composite.Type.cast/1
    (ecto 3.4.6) lib/ecto/changeset.ex:559: Ecto.Changeset.cast_field/8
    (ecto 3.4.6) lib/ecto/changeset.ex:520: Ecto.Changeset.process_param/7
    (elixir 1.10.4) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto 3.4.6) lib/ecto/changeset.ex:497: Ecto.Changeset.cast/6

when you pass in %{"currency" => "USD", "amount" => "0.32"}for a Money.Ecto.Composite.Type

kipcole9 commented 3 years ago

Thanks for the report and apologies for the inconvenience. I had updated all of my libs to work with either Decimal version but I missed that Decimal.parse/1 changed behaviour as well.

I have published money_sql version 1.3.1 to address this issue and it should now be compatible with both Decimal versions 1.x and 2.x.

Updating

Should require no more than:

mix deps.update ex_money_sql

Changelog

coladarci commented 3 years ago

@kipcole9 this update is causing my CI to fail w/ this:

== Compilation error in file lib/cldr/number/parse.ex ==
** (FunctionClauseError) no function clause matching in Keyword.get/3    

    The following arguments were given to Keyword.get/3:

        # 1
        nil

        # 2
        :vsn

        # 3
        nil

    Attempted function clauses (showing 1 out of 1):

        def get(+keywords+, +key+, +default+) when -is_list(keywords)- and +is_atom(key)+

Error:     (elixir 1.10.4) lib/keyword.ex:201: Keyword.get/3
Error:     lib/cldr/number/parse.ex:169: (module)
Error:     (stdlib 3.12.1) erl_eval.erl:680: :erl_eval.do_apply/6
coladarci commented 3 years ago

(I'm being told by @doughsay that this is a caching issue in CI... feel free to ignore......... 🤦 )

kipcole9 commented 3 years ago

Let me know is the issue persists? This error comes from the shim I have in cldr_utils to do version detection at compile tome on Decimal which is needed to determine which version of Decimal.compare/2 or Decimal.cmp/2 to use. And the same for Decimal.parse/1.

The code where is error comes from is:

# cldr_utils/lib/cldr/utils/decimal.ex
decimal_version = Application.ensure_all_started(:decimal) &&
  Application.spec(:decimal, :vsn)
  |> List.to_string()
coladarci commented 3 years ago

clearing all the CI caches fixed this..

kipcole9 commented 3 years ago

Thanks for the update. Your CI must have cached a buggy version of cldr_utils in the one hour period beforeI retired that version in hex.