belaustegui

belaustegui

"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:

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?

Most Liked

zac

zac

I’m running into the same issue with a simple (demo) Ash Framework project. As soon as I added more than the basic persistence, started seeing:

warning: the Inspect protocol has already been consolidated, an implementation for Helpdesk.Support.Ticket has no effect. If you want to implement protocols after compilation or during tests, check the "Consolidation" section in the Protocol module documentation
  lib/helpdesk/support/resources/ticket.ex:1

The code is pretty simple:

defmodule Helpdesk.Support.Ticket do
  use Ash.Resource

  actions do
    defaults [:create, :read, :update, :destroy]

    create :open do
      accept [:subject]
    end
  end

  attributes do
    uuid_primary_key :id

    attribute :subject, :string do
      allow_nil? false
    end

    attribute :status, :atom do
      constraints [one_of: [:open, :closed]]
      default :open
      allow_nil? false
    end
  end
end
lukaszsamson

lukaszsamson

ElixirLS Core Team

ElixirLS bug is already fixed on master

i-n-g-m-a-r

i-n-g-m-a-r

Was this fixed?
Probably it was, the bug seems to have returned.

Last Post!

manuel-rubio

manuel-rubio

I have recently a project using only Ecto, and if I configure a field as redact: true it’s still happening with Ecto 3.13. Even putting consolidate_protocols: Mix.env() != :dev and running in the console (ensuring MIX_ENV=dev) appears the warning.

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement