Can't use my own adapter in Ecto repo config

Hi. I can’t use my own custom adapter:

use Mix.Config

config :connection_cache, Repo,
  # adapter: Ecto.Adapters.Postgres,
  adapter: PostgresAdapterWithoutCache,
  prepare: :unnamed,
  pool: ConnectionCache,
  database: "...",
  username: "..."

It errors with:

== Compilation error on file lib/repo.ex ==
** (ArgumentError) adapter PostgresAdapterWithoutCache was not compiled, ensure it is correct and it is included as a project dependency
    lib/ecto/repo/supervisor.ex:42: Ecto.Repo.Supervisor.parse_config/2
    lib/repo.ex:2: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

It’s in the lib/ dir and if I startup iex -S mix without that adapter, then in the console, it seems to be there:

iex(1)> Code.ensure_loaded? PostgresAdapterWithoutCache

Why? Thanks for the help.

Have you tried putting it as a dependency (lib) and including with mix deps section? I think the problem is order of compilation/loading config that is dofferent than you expect.

You mean making a completely separate project (Github repo) to put it in? Yeah, that’s what I ended up doing and it worked. But I figured one could just specify any available module as an adapter.

What’s weird is that if I put a :timer.sleep(1000) right before the check for that error message (lib/ecto/repo/supervisor.ex:42), then it all works.

Yes, it’s definitely some issue with compilation order. You could try adding require AdapterModule before the call to use Ecto.Repo - this should force the module to be compiled first.