Decoding parameterized field error on schema load
rauann opened this issue · comments
- Elixir 1.12.3
- OTP 24
- Ecto 3.6/3.7
When loading a schema that contains a parameterized
field like Ecto.Enum
, the Ecto.Enum
type loader cannot load the field because it is already decoded as the type that it is expecting:
** (ArgumentError) cannot load `:bar` as type {:parameterized, Ecto.Enum, %{on_dump: %{bar: "bar", foo: "foo"}, on_load: %{"bar" => :bar, "foo" => :foo}, type: :string, values: [:foo, :bar]}} for field :type in %Ecto.Adapters.DynamoDB.TestSchema.Person{__meta__: #Ecto.Schema.Metadata<:loaded, "test_person">, addresses: [], age: nil, country: nil, email: nil, first_name: nil, id: nil, inserted_at: nil, last_name: nil, nil_to_tags: nil, tags_to_tags: nil, type: nil, updated_at: nil}
It is happening because here in the decode_embed
function, ecto is already loading the parameterized
fields.
ecto_adapters_dynamodb/lib/ecto_adapters_dynamodb.ex
Lines 1567 to 1580 in 4762bab
This issue also happens on embedded_schemas
with parameterized
fields. I tried to remove the decode_embed
function usage to test and it seems like we need it for embeds because other fields like utc_datetime
type should already be loaded as its right type which is the opposite behavior for parameterized
fields.
** (ArgumentError) cannot load `"2022-01-04T16:36:56Z"` as type :utc_datetime for field `inserted_at` in schema Ecto.Adapters.DynamoDB.TestSchema.Address
What alternatives do we have to handle this issue? I would be glad to open a merge request with the fix :)
Thank you for alerting us to this issue. We would welcome a merge request. Thank you!