Skip to content

valerio-iachini/ecto_bug_upsert

Repository files navigation

EctoBug

PoC for replicating Ecto upsert bug.

To replicate the bug:

  1. launch mysql and keep it running:

    docker compose up
  2. 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]
}

Working case

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]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages