PoC for replicating Ecto upsert bug.
To replicate the bug:
-
launch mysql and keep it running:
docker compose up
-
execute tests:
mix deps.get && mix compile mix ecto.create mix ecto.migrate iex -S mix run -e "EctoBug.replicate"
OR
mix deps.get && mix test
Expected result: the ID of the returned updated author is not nil
.
Actual result:
%EctoBug.Schema.Author{
__meta__: #Ecto.Schema.Metadata<:loaded, "authors">,
counter: nil,
id: nil,
inserted_at: ~N[2022-10-13 09:28:11],
name: "author1",
posts: #Ecto.Association.NotLoaded<association :posts is not loaded>,
updated_at: ~N[2022-10-13 09:28:11]
}
If we put a :timer.sleep
after each write, the ID of the updated record is not nil
:
%EctoBug.Schema.Author{
__meta__: #Ecto.Schema.Metadata<:loaded, "authors">,
counter: nil,
id: 1,
inserted_at: ~N[2022-10-13 09:28:11],
name: "author1",
posts: #Ecto.Association.NotLoaded<association :posts is not loaded>,
updated_at: ~N[2022-10-13 09:28:11]
}