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
Form validation on an "for_update" form crashes with
** (Decimal.Error) : number parsing syntax: "x"
when passing a value for a decimal field which cannot be parsed to decimal (e.g. "x")
To Reproduce
error is triggered in call to Comp.not_equal? in AshPhoenix.Form.attributes_changed?/1
you can trigger the error standalone like this:
Comp.not_equal?(Elixir.Decimal.new("1.5"),"x")
Expected behavior
technically it is correct for Comp to fail when comparing apples and oranges.
But in this case i'd like attributes_changed?/1 to return true, because a change of attribute is present, although an invalid one.
the invalid format can then be catched later on and presents an "invalid value" message in the UI.
i solved it in my project by redefining Comparable.Comparable.Type.BitString.To.Decimal so that
comparing a decimal with a non-decimal always returns :gt
lib/my_app/my_decimal_comp.ex:
import Ash.Type.Comparable
defcomparable left :: Decimal, right :: BitString do
case Decimal.cast(right) do
:error -> :gt
_ -> Decimal.compare(left, Ash.Type.Decimal.new(right))
end
end
** Runtime **
Ash version
2.4.20
The text was updated successfully, but these errors were encountered:
Describe the bug
Form validation on an "for_update" form crashes with
when passing a value for a decimal field which cannot be parsed to decimal (e.g. "x")
To Reproduce
error is triggered in call to Comp.not_equal? in AshPhoenix.Form.attributes_changed?/1
you can trigger the error standalone like this:
Expected behavior
technically it is correct for Comp to fail when comparing apples and oranges.
But in this case i'd like attributes_changed?/1 to return true, because a change of attribute is present, although an invalid one.
the invalid format can then be catched later on and presents an "invalid value" message in the UI.
i solved it in my project by redefining Comparable.Comparable.Type.BitString.To.Decimal so that
comparing a decimal with a non-decimal always returns :gt
** Runtime **
2.4.20
The text was updated successfully, but these errors were encountered: