Blibs
Blibs
Explore posts from servers
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
But anyway, you can ignore that error, it is totally in my side hahahah. In any case your change to main totally fixed it! Thanks a bunch 🥳
13 replies
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
I guess there is some new check that Ash does that started checking for this in generic actions?
13 replies
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
Oh, actually, that type module path is just wrong, wth.
13 replies
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
But, besides that, seems like the change in main fixed the issue with off_market 😄
13 replies
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
Updating to main seems like it break some generic actions like this one:
action :changelog, {:array, Changelog} do
alias Actions.Changelog

description "Returns a list of changes done to the offer"

argument :id, :uuid, allow_nil?: false

run &Changelog.run/2
end
action :changelog, {:array, Changelog} do
alias Actions.Changelog

description "Returns a list of changes done to the offer"

argument :id, :uuid, allow_nil?: false

run &Changelog.run/2
end
It gives the error:
** (RuntimeError) {:array, Marketplace.Markets.Offer.Changelog} is not a valid type.
** (RuntimeError) {:array, Marketplace.Markets.Offer.Changelog} is not a valid type.
13 replies
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
Also, in case it helps, here is the full embedded resource that I'm trying to remove from the form:
defmodule Marketplace.Markets.Property.OffMarket do
@moduledoc false

use Ash.Resource,
data_layer: :embedded,
extensions: [AshGraphql.Resource]

code_interface do
define_for Marketplace.Markets

define :new
end

attributes do
alias Marketplace.Ash.Types.PhoneNumber

attribute :agent_name, :string
attribute :agent_phone_number, PhoneNumber

attribute :company_name, :string, allow_nil?: false
attribute :company_phone_number, PhoneNumber
end

graphql do
type :off_market
end

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

create :new, primary?: true
end
end
defmodule Marketplace.Markets.Property.OffMarket do
@moduledoc false

use Ash.Resource,
data_layer: :embedded,
extensions: [AshGraphql.Resource]

code_interface do
define_for Marketplace.Markets

define :new
end

attributes do
alias Marketplace.Ash.Types.PhoneNumber

attribute :agent_name, :string
attribute :agent_phone_number, PhoneNumber

attribute :company_name, :string, allow_nil?: false
attribute :company_phone_number, PhoneNumber
end

graphql do
type :off_market
end

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

create :new, primary?: true
end
end
13 replies
AEAsh Elixir
Created by Blibs on 9/19/2023 in #support
AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error
Got more info, the error is generated in ash_postgres, more specifically in AshPostgres.DataLayer.handle_raised_error/4 It happens because of this ecto error:
e #=> %Ecto.Query.CastError{
type: {:parameterized, Marketplace.Markets.Property.OffMarket.EctoType, []},
value: nil,
message: "value `nil` in `update` cannot be cast to type #Marketplace.Markets.Property.OffMarket.EctoType<[]> in query:\n\nfrom p0 in Marketplace.Markets.Property,\n as: 0,\n where: p0.id == ^\"db7c7c4a-2c99-40b8-9204-f9d6dad4dd91\",\n update: [\n set: [\n updated_at: ^~U[2023-09-19 00:32:56.521021Z],\n processing_status: ^:running,\n off_market: ^nil\n ]\n],\n select: [:id]\n"
}
e #=> %Ecto.Query.CastError{
type: {:parameterized, Marketplace.Markets.Property.OffMarket.EctoType, []},
value: nil,
message: "value `nil` in `update` cannot be cast to type #Marketplace.Markets.Property.OffMarket.EctoType<[]> in query:\n\nfrom p0 in Marketplace.Markets.Property,\n as: 0,\n where: p0.id == ^\"db7c7c4a-2c99-40b8-9204-f9d6dad4dd91\",\n update: [\n set: [\n updated_at: ^~U[2023-09-19 00:32:56.521021Z],\n processing_status: ^:running,\n off_market: ^nil\n ]\n],\n select: [:id]\n"
}
What I don't get is why it can't put off_market as nil, it is set as nullable in my resource:
attribute :off_market, OffMarket, allow_nil?: true
attribute :off_market, OffMarket, allow_nil?: true
13 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
Not sure why I couldn't trigger it when I run the same code but as a ash_phoenix unit test 🤔
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
Can confirm, that fixed it!
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
Damn that was fast!
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
maybe it only doesn't work on arrays? not sure
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
@Zach Daniel when you have some free time can you try it out? Basically you just need to open iex and run:
# This will create the resource, create the form for update and run submit on it, it will return an error with the form:
{:error, form} = AshPhoenixEmbeddedTest.Run.run()

# Now if you run this:
AshPhoenix.Form.errors(form, for_path: :all)

# You should see this:
# %{
# [:images, 0] => [url: "is required"],
# [:images, 1] => [uuid: "is required"],
# [:images, 1, :thumbnail] => [url: "is required"]
# }
# This will create the resource, create the form for update and run submit on it, it will return an error with the form:
{:error, form} = AshPhoenixEmbeddedTest.Run.run()

# Now if you run this:
AshPhoenix.Form.errors(form, for_path: :all)

# You should see this:
# %{
# [:images, 0] => [url: "is required"],
# [:images, 1] => [uuid: "is required"],
# [:images, 1, :thumbnail] => [url: "is required"]
# }
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
All right! I was able to create a small project that reproduces the issue
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
I will try to move it to another standalone project right now and see if I can make it trigger, hopefully I will be able to do that and give you a link to the project at least 😅
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
You mean in my project? I looked into mix.lock and it is getting the latest version
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
The only thing that I can think that is different is that I have more ash libraries in my project, ash_authentication_phoenix, ash_graphql, etc. But I'm not using them in these resources, so I'm not sure if they somehow affect AshPhoenix.Form in some way
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
I will try to move it into a separated small project and see if I can reproduce it there
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
So, @Zach Daniel I created a unit test for it in AshPhoenix, but weirdly enough I can't reproduce it running from it, only inside my project, even thought the code and libraries versions are exactly the same
49 replies
AEAsh Elixir
Created by Blibs on 9/15/2023 in #support
AshPhoenix.Form fails in submit without errors with embedded resources
I will try to create a unit test, but here is a small examply that can reproduce the issue:
defmodule Marketplace.Markets.Property2.SubImage do
use Ash.Resource, data_layer: :embedded

attributes do
attribute :url, :string, allow_nil?: false
end

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


defmodule Marketplace.Markets.Property2.Image do
alias Marketplace.Markets.Property2.SubImage

use Ash.Resource, data_layer: :embedded

attributes do
attribute :uuid, :uuid, allow_nil?: false

attribute :thumbnail, SubImage, allow_nil?: false
end

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

defmodule Marketplace.Markets.Property2 do
@moduledoc false

alias Marketplace.Markets.Property2.Image

use Ash.Resource, data_layer: Ash.DataLayer.Ets

code_interface do
define_for Marketplace.Markets

define :create
end

attributes do
uuid_primary_key :id

attribute :images, {:array, Image}, default: []
end

actions do
defaults [:create, :update, :read]
end
end
defmodule Marketplace.Markets.Property2.SubImage do
use Ash.Resource, data_layer: :embedded

attributes do
attribute :url, :string, allow_nil?: false
end

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


defmodule Marketplace.Markets.Property2.Image do
alias Marketplace.Markets.Property2.SubImage

use Ash.Resource, data_layer: :embedded

attributes do
attribute :uuid, :uuid, allow_nil?: false

attribute :thumbnail, SubImage, allow_nil?: false
end

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

defmodule Marketplace.Markets.Property2 do
@moduledoc false

alias Marketplace.Markets.Property2.Image

use Ash.Resource, data_layer: Ash.DataLayer.Ets

code_interface do
define_for Marketplace.Markets

define :create
end

attributes do
uuid_primary_key :id

attribute :images, {:array, Image}, default: []
end

actions do
defaults [:create, :update, :read]
end
end
And then run:
alias Marketplace.{Markets, Markets.Property2}

images = [
%{uuid: Ecto.UUID.generate(), thumbnail: %{url: "some_url"}},
%{uuid: Ecto.UUID.generate(), thumbnail: %{url: "some_url"}}
]

{:ok, property} = Property2.create(%{images: images})

form = AshPhoenix.Form.for_update(property, :update, api: Markets, forms: [auto?: true])

# This will fail
AshPhoenix.Form.submit(form, params: %{})
alias Marketplace.{Markets, Markets.Property2}

images = [
%{uuid: Ecto.UUID.generate(), thumbnail: %{url: "some_url"}},
%{uuid: Ecto.UUID.generate(), thumbnail: %{url: "some_url"}}
]

{:ok, property} = Property2.create(%{images: images})

form = AshPhoenix.Form.for_update(property, :update, api: Markets, forms: [auto?: true])

# This will fail
AshPhoenix.Form.submit(form, params: %{})
49 replies