Has `Ecto` stopped supporting decimal-related options in schema field definition?

Question

Has Ecto stopped supporting decimal-related options in schema field definition?

Error

Console error on mix compile --force (since updating ecto this morning)

Code

The ecto schema uses :decimal with extra options

field(:retail_price, :decimal, precision: 8, scale: 2)
** (ArgumentError) invalid option :precision for field/3
    (ecto 3.8.0) lib/ecto/schema.ex:2214: Ecto.Schema.check_options!/3
    (ecto 3.8.0) lib/ecto/schema.ex:1911: Ecto.Schema.__field__/4

Thanks
:pray:

Afaik those options were never supported on the field macro, but only on the add macro in migrations. Ecto only recently added code for validating those field options though.

1 Like

Thanks, and you are a 100% right.
I just checked, and it does not enforce any validation based on that precision/scale prior Ecto3.8 when it compiled error-free.

  schema "test_schema" do
    field(:value, :decimal, precision: 2, scale: 2)
  end

  def changeset(schema, attrs) do
    cast(schema,  attrs, ~w(value)a)
  end

iex(35)> a = %{value: Decimal.new("222222.007000")}                
%{value: #Decimal<222222.007000>}

iex(36)> changeset %TestSchema{}, a                            
#Ecto.Changeset<
  action: nil,
  changes: %{value: #Decimal<222222.007000>},
  errors: [],
  data: #TestSchema<>,
  valid?: true
>
2 Likes