"The Inspect protocol has already been consolidated" for Ecto schema with redacted field

I’ve recently started a new Phoenix project using Elixir 1.11, Phoenix 1.5 and Ecto 3.5.

Everything runs smoothly but there is a recurrent warning in ElixirLS which I can not fix. The warning says:

the Inspect protocol has already been consolidated, an implementation for MyApp.User has no effect. If you want to implement protocols after compilation or during tests, check the “Consolidation” section in the Protocol module documentation

The warning is highlighted in the Ecto schema declaration:

image

The thing is: the module does not implement the Inspect protocol. I know I can disable protocol consolidation in development to make this warning disappear, but I would like to know what is causing it. It only happens in this schema and not in the resto of Ecto schemas I have implemented.

EDIT

I’ve dived into the Ecto.Schema.schema() code and found this code which I belive is causing the warning:

        if redacted_fields != [] and not List.keymember?(@derive, Inspect, 0) and
             @ecto_derive_inspect_for_redacted_fields do
          @derive {Inspect, except: @ecto_redact_fields}
        end

My schema has a field :password, :string, virtual: true, redact: true which triggers this code and derives the Inspect protocol for my schema.

So, now that I know where this comes from. Is there a way to fix this warning? Should I report it as a bug in Ecto?

3 Likes

Why are your protocols consolidated during development?

Well, I didn’t change any configuration related to this. So it seems to be the default behaviour for Elixir projects.

ElixirLS recompiles the project when saving updated files and it is the one triggering this warnings. Running mix compile manually does not show any warning.