Ash stopped working with ExMachina. Ash 2.5.10
Hello,
I've been using Ash with ExMachina successfully up to this point. Recently I've wanted to upgrade Ash from 2.5.9 to 2.6.0, alongside AshPostgres from 1.3.3 to 1.3.8. I've tested combinations of different Ash and AshPostgres combinations to narrow down the issue. It appears to be caused by Ash 2.5.10. Specifically this commit https://github.com/ash-project/ash/commit/2787b5074b8b339057af6f0bc4ee3db5abf7c60d
Our factory:
When I try to do
insert(:resource, some_field: "some_value)
I get the following error
Is there any possibility to bring back the support for ExMachina?19 Replies
π€ I don't think that we can undo that change realistically.
but hopefully we can find some other way to get compatibility
Is there a stacktrace for that error?
Yeah, sorry.
I think we may need to clone the EctoStrategy and make an
AshStrategy
, or make a PR to the ecto strategy to give %Ash.NotLoaded{}
the same treatment that Ecto.NotLoaded
getsYeah, that was my first step, but that kinda seems like a lot of unnecessary work to just handle that case.
My second thought was to allow developer to opt-out of adding Ecto Relationship by wrapping the added
case
statement in an unless
. Something like
And then either in the resource itself or by config file pass disable_ecto_relationship: true
But I lack the knowledge of Ash internals to be sure if it's a viable solutionπ€ you might also be able to do this
its a bit of a hack, but might work
in the factory, I mean
Ash also has some seeding tools FWIW
Found 1 Code results in all libraries:
* Ash.Seed: https://ash-hq.org/docs/module/ash/2.6.0/ash-seed
The
AshPostgres.DataLayer.to_ecto(%YourStuff{})
works. π Thanks!
I've written simple ExMachina strategy to do that on every insert. But I do not know to which repo(if at all) should it go.
EDIT:
Added from_ecto()
at the end of handle_insert
as Zach suggestedYou might want to add a
from_ecto/1
call at the end also so it will definitely play nicely with the rest of Ash stuff.
I'm also not sure where that should go π Where does the Ecto
related stuff go fro ex_machina
? Do they just have it all in one repo? For now, I might just keep it in your app, this forum thread will be searchable for others with similar issues πExMachina has built-in Ecto support so it's in the main library, but I don't think we will manage to add Ash support there π Yeah I think it's kinda too specific to add it to Ash. But if there's a need for that later I think it could go into
ash_postgres
Yeah, thats a good point. We can conditionally compile it if
ExMachina
is compiled tooHi Myrmyr, I have the same issue, where do you put this file? Do you just
use Ash.ExMachina
instead of use ExMachina.Ecto
?I actually put these modules in a separate files in
support
folder of test
directory. Then, just as you've described, in factory I do use Ash.ExMachina, repo: MyApp.Repo
instead of ExMachina.Ecto, repo: MyApp.Repo
Not sure if anything changed recently, but I tried this solution and it doesn't work for some reason. None of the records I try to create are persisted in the database.
they should only live for the life of each test, is that what you're seeing?
You have to do a bit more with the ExMachina.Ecto and ExMachina.EctoStrategy based on when I took a swing at this a little over a month ago.
I'll try to do a writeup in the next week, but if you're not already leveraging ExMachina throughout your codebase you may better off giving Ash.Seed a shot.
π
I didn't know Ash.Seed exists. I'll check this out. Thanks!
It doesn't exist even inside the test. As in the struct says it's loaded, but there is no
id
, inserted_at
, and updated_at
which implies the record didn't get created.π€ Yeah, hard to say whats up there. For my piece, I'd like to just improve
Ash.Seed
until there is no compelling reason to use ex_machina.I tried
Ash.Seed
and it looks like it's enough for me. I wish I'd known about that module a lot earlier lol