Dependency compilation issue, but only in test environment

I feel like I’m seeing some kind of bug in mix/elixir. anyone can verify this, it’s from the GitHub - ash-project/ash_postgres: A postgresql datalayer for the Ash Framework repo.

MIX_ENV=test mix compile isn’t properly compiling the ash_sql dependency before compiling the ash_postgres app?

If I run mix compile , it works just fine. Its only in test that it doesn’t

It complains about this line:

use AshSql.Implementation

But if I put this right above that line

Code.ensure_compield!(AshSql.Implementation)

it success in ensuring that its compiled, but still fails on that line saying:

    error: module AshSql.Implementation is not loaded and could not be found. This may be happening because the module you are trying to load directly or indirectly depends on the current module
    │
  4 │   use AshSql.Implementation
    │   ^^^^^^^^^^^^^^^^^^^^^^^^^
    │
    └─ lib/sql_implementation.ex:4: AshPostgres.SqlImplementation (module)

Anyone have any ideas?

Okay, small update, the bit about having Code.ensure_compiled above it is not right. If I comment everything else out and just add that, it properly fails. Still, very strange as it compiles w/o issue not in test.

Okay, I figured it out. We do a weird thing in our mix.exs because ash_postgres doesn’t need to ship with an application runtime normally (as users host their repos in their own application), but we need one for testing so we can start our repos.

  if Mix.env() == :test do
    def application() do
      [
        applications: [:ecto, :ecto_sql, :jason, :ash, :postgrex, :tools, :benchee, :xmerl, :ash_sql], # <- had to add `ash_sql` here
        mod: {AshPostgres.TestApp, []}
      ]
    end
  end

1 Like

This specific issue (the list in applications not matching what’s in deps) is why extra_applications exists:

Do your tests pass if you replace the code in mix.exs with:

  if Mix.env() == :test do
    def application() do
      [
        extra_applications: [:tools, :xmerl],
        mod: {AshPostgres.TestApp, []}
      ]
    end
  end
3 Likes

ahhh, I didn’t even notice that I was using applications instead of extra_applications. Makes perfect sense now :slight_smile: Thank you! Using extra_applications does indeed solve the issue :partying_face: :bowing_man:

2 Likes