Closed coladarci closed 1 year ago
Apologies, that's extremely inconvenient.
The type {"USD", Decimal.new("50.00")}
is the format that comes back from Postgrex
for the money_with_currency
composite type in Postgres. Is that correct in your case?
If so, the likely culprit is ex_money_sql
and as a first measure I'd recommend first moving back to ex_money_sql 1.9.0
.
There were some changes to the type definition in 1.9.2 that related to embedded schemas. By any chance would you be using embedded schemas with a money type in Postgres? That would be a second line of enquiry. Because money_sql
itself doesn't use JSON encoding directly - it's only (as I understand it) when Ecto
is encoding a map()
type field or an embedded schema.
Hope that gives you a more specific place to look and one thing to try. If you are able to isolate the Ecto schema that is raising the issue and you are able to share it that would be extremely helpful.
Thanks! Yes we definitely embed Money Objects - we can try rolling back, but what can I do to help sort out the potential bug around embedded moneys?
My guess (and it's a guess) is that in your embedded schemas the type is Money.Ecto.Composite.Type
when it needs to be Money.Ecto.Map.Type
. It seems to have worked a bit by accident in earlier releases and I didn't have good enough test coverage.
I merged a PR that fixed some issues with embedded schemas but it may have introduced the issue you are seeing. If money_sql
version 1.9.1 works but 1.9.2 doesn't then that helps narrow down where to look. I'm a little surprised though because the tuple form like {"USD", Decimal.new("50.00")}
can only come from the composite type.
An embedded money type needs to be Money.Ecto.Map.Type
like this:
schema "organizations" do
embeds_many :customers, Customer do
field :name, :string
field :revenue, Money.Ecto.Map.Type, default: Money.new(:USD, 0)
end
end
If 1.9.1
works and 1.9.2
doesn't then its isolated to the referenced PR and I have at least somewhere to start looking.
I can confirm that flipping to Money.Ecto.Map.Type
solves my problems!
Phew, extremely happy to hear that. I will make a much clearer note in the readme and the changelog. The previous behaviour was erroneous and I'm surprised it actually worked - but clearly not a great upgrade experience.
What made this wonderful is that I had zero doubt you'd have an answer within 24 hours (and more likely within a few) and you did not disappoint. I appreciate you and this library more than you can know!
Thanks for the kind words Greg, it's much appreciated and definitely keeps my. motivation high.
I've updated the readme to be as super clear and obvious as possible. And I've updated the changelog too.
Hopefully that means other people won't have the same issue I put you through.
Heyya -
When running the following update:
I suddenly get the following:
There isn't a good stack trace to point to anything specific, but I'm hoping you have some ideas?
Appreciate any ideas!