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?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 10 of 11 Posts
josevalim
You need to move the implementations to when the protocol is defined, or define them conditionally only for tests.
Once the type system is in place, if we don’t have the protocol definition, it will be impossible to check if the implementation is correct.
sezaru
Do you mean move this code to the same file of the implementation and adding
To it?
Is there some way to declare the dependency on that module before calling defimpl so I don’t have to move test code from
test/tolib/?josevalim
My understanding is that the protocol is only defined in test, right? So you could also move the implementation to test.
sezaru
The protocol and implementation of it (
defimpl) is only in test, but the modelu that the implementation references is in lib.In other words, the module
Core.Marketplace.Chat.PropertyMessagein located inlib/core/marketplace/chat/property_message.ex, thedefimpl Core.Support.Factory.Builder, for: Core.Marketplace.Chat.PropertyMessageis located intest/support/factory/marketplace/chat/property_message.exand the protocol declarationdefprotocol Core.Support.Factory.Builderis located intest/support/factory/builder.ex.Before 1.19, this would work just fine, after 1.19, it started giving the warning/error I mentioned in the first post.
josevalim
This should indeed work. Any chance you can isolate it into a reproducible example so we can address it?
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 compileit will generate the following warning:
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:This lines add the embedded Ash resource
Attachmentas an attribute of my Ash resourcePropertyMessage.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
If I remove Ash, then it works. By using
–profile time, we can see that Ash is deadlocking the compiler:The fact that attachment is waiting for
:embeddedalso 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.sezaru
Thanks for finding the root cause @josevalim I will create an issue in Ash’s repo and link to this post.
zachdaniel
Pretty much all of our validations happen in verifiers, but I will look into this for sure
zachdaniel
This was indeed an issue w/ the
:embeddedreference there. In Ash, there is a short-hand ofdata_layer: :embedded. We were treating that as an extension module insparkand attempting to call a function on it. This is fixed in2.3.7of spark.