AE
Ash Elixir•2y ago
Blibs

AshPhoenix.Form fails to submit with Ash.Error.Query.InvalidFilterValue error

Hey there, I'm not sure exactly what is happenig, but I have a embedded resource that was inserted into my resource, when I try to update it via AshPhoenix, by first calling AshPhoenix.Form.remove_form and then AshPhoenix.Form.submit, I get this error:
[warning] Unhandled error in form submission for Marketplace.Markets.Property.update

This error was unhandled because it did not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Query.InvalidFilterValue) Invalid filter value `nil` supplied in `#Ecto.Changeset<action: nil, changes: %{updated_at: ~U[2023-09-19 00:18:43.738483Z], off_market: nil, processing_status: :running}, errors: [], data: #Marketplace.Markets.Property<>, valid?: true>`
[warning] Unhandled error in form submission for Marketplace.Markets.Property.update

This error was unhandled because it did not implement the `AshPhoenix.FormData.Error` protocol.

** (Ash.Error.Query.InvalidFilterValue) Invalid filter value `nil` supplied in `#Ecto.Changeset<action: nil, changes: %{updated_at: ~U[2023-09-19 00:18:43.738483Z], off_market: nil, processing_status: :running}, errors: [], data: #Marketplace.Markets.Property<>, valid?: true>`
Any idea on what can be the issue here? I'm trying to create a small example that triggers this but without too much success.
6 Replies
Blibs
BlibsOP•2y ago
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
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
ZachDaniel
ZachDaniel•2y ago
Can you try ash main for me?
Blibs
BlibsOP•2y ago
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.
But, besides that, seems like the change in main fixed the issue with off_market 😄
ZachDaniel
ZachDaniel•2y ago
🤔 Is that type defined in the same file as the resource? is that the actual type name?
Blibs
BlibsOP•2y ago
Oh, actually, that type module path is just wrong, wth. I guess there is some new check that Ash does that started checking for this in generic actions? 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 🥳
ZachDaniel
ZachDaniel•2y ago
yes, we added a check for exactly that that was missing 😆

Did you find this page helpful?