sezaru

sezaru

Defimpl for some other module stopped working after upgrade to 1.19

Hey guys, I have some files that implement a protocol for some resources for my tests (they are only compiled when running tests:

defimpl Core.Support.Factory.Builder, for: Core.Marketplace.Chat.PropertyMessage do

  def attributes(_message) do
    ...
  end

  def build!(user, _opts) do
    ...
  end
end

Before 1.19, this would work just fine, after the upgrade, I now get this warning:

    warning: you are implementing a protocol for Core.Marketplace.Chat.PropertyMessage but said module is not available. Make sure the module name is correct. If Core.Marketplace.Chat.PropertyMessage is an optional dependency, please wrap the protocol implementation in a Code.ensure_loaded?(Core.Marketplace.Chat.PropertyMessage) check
    │
  1 │ defimpl Core.Support.Factory.Builder, for: Core.Marketplace.Chat.PropertyMessage do
    │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ test/support/factory/marketplace/chat/property_message.ex:1: (file)

and then the tests that expect this will break.

Did something change in 1.19 related to defimpl or is this a bug?

Most Liked

zachdaniel

zachdaniel

Creator of Ash

This was indeed an issue w/ the :embedded reference there. In Ash, there is a short-hand of data_layer: :embedded. We were treating that as an extension module in spark and attempting to call a function on it. This is fixed in 2.3.7 of spark.

sezaru

sezaru

Hey @josevalim I made a reproducible example, here is the link: GitHub - sezaru/test_new_elixir · GitHub

Basically you just need to compile it using MIX_ENV=test mix compile

it will generate the following warning:

> MIX_ENV=test mix compile --force
Compiling 6 files (.ex)
    warning: you are implementing a protocol for Core.Marketplace.Chat.PropertyMessage but said module is not available. Make sure the module name is correct. If Core.Marketplace.Chat.PropertyMessage is an optional dependency, please wrap the protocol implementation in a Code.ensure_loaded?(Core.Marketplace.Chat.PropertyMessage) check
    │
  1 │ defimpl Core.Support.Factory.Builder, for: Core.Marketplace.Chat.PropertyMessage do
    │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ test/support/factory/marketplace/chat/property_message.ex:1: (file)

Making the example, basically what makes this warning appears or not is the line 11 of the file lib/core/marketplace/chat/property_message.ex:

    attribute :attachments, {:array, Attachment}, default: []

This lines add the embedded Ash resource Attachment as an attribute of my Ash resource PropertyMessage.

If I remove that line, then the warning disappears.

The same code works fine in Elixir 1.18.

Maybe @zachdaniel knows why this triggers the warning?

josevalim

josevalim

Creator of Elixir

If I remove Ash, then it works. By using –profile time, we can see that Ash is deadlocking the compiler:

$ MIX_ENV=test mix compile --force --profile time
Compiling 6 files (.ex)
[profile]      9ms compiling +      0ms waiting while compiling lib/core/application.ex
[profile]     31ms compiling +      0ms waiting while compiling test/support/factory/builder.ex
[profile]    164ms compiling +      0ms waiting while compiling lib/core/marketplace/chat.ex
[profile] Finished deadlock resolution in 0ms
[profile]     15ms compiling +    133ms waiting for module Core.Marketplace.Chat.PropertyMessage while compiling test/support/factory/marketplace/chat/property_message.ex
[profile]                    |     24ms waiting for module Core.Support.Factory.Builder while compiling test/support/factory/marketplace/chat/property_message.ex
[profile] Finished deadlock resolution in 0ms
[profile]    447ms compiling +    167ms waiting for module :embedded while compiling lib/core/marketplace/chat/attachment.ex
[profile]    239ms compiling +    552ms waiting for module Core.Marketplace.Chat.Attachment while compiling lib/core/marketplace/chat/property_message.ex

The fact that attachment is waiting for :embedded also points to what is more likely a bug. My suggestion is for Ash to move some of the validations in its DSL to verify callbacks. If the compiler is deadlocked, then it assumes the modules are not there, leading to the warning.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
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
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement