What is tripping up my preload after Ecto 3.4.6 upgrade?

I’ve updated Ecto 3.4.6 and am now seeing a new failure:

This fails:

      from(Timecard, preload: :approvals)
      |> Repo.all()

The problem is specific to my Schema structures - due to the :approver_id and Approver embed of the Approval struct I think:

defmodule Ev2.Timecards.Approval do
  schema "timecard_approvals" do
    belongs_to(:timecard, Timecard)
    belongs_to(:data, TimecardData, foreign_key: :data_id)

    field(:approver_id, :integer)
    field(:datetime_approved, :utc_datetime)

    embeds_one(:approver, Approver)
  end
end

defmodule Ev2.Timecards.Approver do
  embedded_schema do
    field(:user_id, :integer)
    field(:first_name)
    field(:last_name)
    field(:email)
  end
end

defmodule Ev2.Timecards.Timecard do
  schema "timecards" do
    has_many(:approvals, Approval)
    has_many(:timecard_data, TimecardData, on_delete: :delete_all)
  end
end

The error:

     ** (ArgumentError) cannot load `42382` as type :binary_id for field `id` in schema Ev2.Timecards.Approver
     code: |> Repo.all()
     stacktrace:
       (ecto 3.5.1) lib/ecto/schema/loader.ex:76: anonymous fn/5 in Ecto.Schema.Loader.unsafe_load/4
       (elixir 1.11.0) lib/enum.ex:2181: Enum."-reduce/3-lists^foldl/2-0-"/3
       (ecto 3.5.1) lib/ecto/embedded.ex:60: Ecto.Embedded.load/3
       (ecto 3.5.1) lib/ecto/type.ex:870: Ecto.Type.process_loaders/3
       (ecto 3.5.1) lib/ecto/repo/queryable.ex:378: Ecto.Repo.Queryable.struct_load!/6
       (ecto 3.5.1) lib/ecto/repo/queryable.ex:210: anonymous fn/5 in Ecto.Repo.Queryable.preprocessor/3
       (elixir 1.11.0) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
       (ecto 3.5.1) lib/ecto/repo/queryable.ex:197: Ecto.Repo.Queryable.execute/4
       (ecto 3.5.1) lib/ecto/repo/queryable.ex:17: Ecto.Repo.Queryable.all/3
       (elixir 1.11.0) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
       (ecto 3.5.1) lib/ecto/repo/queryable.ex:198: Ecto.Repo.Queryable.execute/4
       (ecto 3.5.1) lib/ecto/repo/queryable.ex:17: Ecto.Repo.Queryable.all/3
       test/ev2/lib/schedule/tasks/approve_test.exs:71: (test)

Deps from mix.exs

      {:phoenix_ecto, "~> 4.1.0"},
      {:ecto_sql, "~> 3.4.1"}, 
      {:phoenix, "~> 1.5.0"},

This is what the docs say on embedded_schema:

Embedded schemas by default set the primary key type to :binary_id but such can be configured with the @primary_key attribute.

By the error message it looks like your id is an integer.

I am guessing this is something to do with the bottom bug fix from Ecto 3.4.6:

Screenshot 2020-10-09 at 15.58.13

??

Perhaps this issue is helpful for me:

Thanks @sfusato, you are right, but it’s something within ecto that is causing the change. Ecto is generating the id’s and upgrading 3.4.5 -> 3.4.5 seems to generate the id differently, which seems to cause this error