Ecto (mysql) and UUID

Hi,
I’m having a similar issue with mysql and uuid, but can’t find a solution.
Creating and reading an entry works in about 80% of the time, but in the other cases the id in the database will be different than the one in the changeset.

i wrote a simple test that inserts and then reads again like this:

  def failtest(conn, _params) do
    insert(conn, 0) |> index(nil)
  end

  def insert(conn, count)do
    changeset = Picture.changeset(%Picture{}, %{name: "test"<>Integer.to_string(count)})
    Repo.insert(changeset)
    |> case do
      {:ok, picture} ->
        cond do
          Repo.one(from p in Picture, where: p.id == ^picture.id) ->
            if count < 100 do
              insert(conn, count+1)
            else
              conn |> put_flash(:info, "finished")
            end
          true ->
            conn |> put_flash(:error, "couldn't find entry")
          end
      {:error, _param} ->
        conn |> put_flash(:error, "couldn't insert")
      end
  end

Usually it will abort somewhere between 2 and 15 entries created.

Does someone have an idea about that?

I updated my test to output the uuid’s:
insert: a0569da7-4201-47a8-bab0-4aca263b735a => ok
insert: cc2d9293-5898-4118-8352-c192090bf6ef => fail, got new id: 3f2d3f3f-583f-4118-3f52-3f3f090b3f00

another run:
insert: 2361f715-48f9-4574-9cb2-379883a8adc4 => got new id: 23613f15-483f-4574-3f3f-373f3f3f3f00

interesting: the new id’s are sharing some parts with the original ones…

/e: now found this: binary id odd bug · Issue #2602 · elixir-ecto/ecto · GitHub
i’ll try that later, hope it fixes the problem :slight_smile:

/e²: Fixed it by adding utf8mb4 to the repo config (config/dev.exs):

# Configure your database
config :testproject, Testproject.Repo,
  username: "xyz",
  password: "xyz",
  database: "xyz",
  hostname: "xyz",
  charset: "utf8mb4",
  collate: "utf8mb4_unicode_ci"
3 Likes