Unable to create a resource with an array attribute

defmodule Galenic.Categorization.Request do
use Ash.Resource,
domain: Galenic.Categorization,
data_layer: AshPostgres.DataLayer

postgres do
table "categorization_requests"
repo Galenic.Repo
end

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

read :read do
primary? true
prepare build(load: [:source_file, :results_file])
end
end

attributes do
uuid_v7_primary_key :id

attribute :columns, {:array, :string} do
constraints allow_empty?: false
allow_nil? false
public? true
end
end
...
defmodule Galenic.Categorization.Request do
use Ash.Resource,
domain: Galenic.Categorization,
data_layer: AshPostgres.DataLayer

postgres do
table "categorization_requests"
repo Galenic.Repo
end

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

read :read do
primary? true
prepare build(load: [:source_file, :results_file])
end
end

attributes do
uuid_v7_primary_key :id

attribute :columns, {:array, :string} do
constraints allow_empty?: false
allow_nil? false
public? true
end
end
...
with {:ok, df} <- DataFrame.from_csv(path),
columns <- DataFrame.names(df) |> IO.inspect(),
changeset <-
Ash.Changeset.for_create(Request, :create, %{columns: columns}) |> IO.inspect(),
{:ok, request} <- Ash.create(changeset) |> IO.inspect(),
{:ok, request} <-
Ash.load(request, :source_file)
|> IO.inspect(),
:ok <-
DataFrame.to_csv(df, request.source_file) do
{:ok, request}
end
with {:ok, df} <- DataFrame.from_csv(path),
columns <- DataFrame.names(df) |> IO.inspect(),
changeset <-
Ash.Changeset.for_create(Request, :create, %{columns: columns}) |> IO.inspect(),
{:ok, request} <- Ash.create(changeset) |> IO.inspect(),
{:ok, request} <-
Ash.load(request, :source_file)
|> IO.inspect(),
:ok <-
DataFrame.to_csv(df, request.source_file) do
{:ok, request}
end
["PMID", "Title", "Authors"]
#Ash.Changeset<
domain: Galenic.Categorization,
action_type: :create,
action: :create,
attributes: %{},
relationships: %{},
errors: [
%Ash.Error.Invalid.NoSuchInput{
calculation: nil,
resource: Galenic.Categorization.Request,
action: :create,
input: :columns,
inputs: MapSet.new([]),
did_you_mean: [],
splode: nil,
bread_crumbs: [],
vars: [],
path: [],
stacktrace: #Splode.Stacktrace<>,
class: :invalid
}
],
data: %Galenic.Categorization.Request{
id: nil,
columns: nil,
__meta__: #Ecto.Schema.Metadata
},
valid?: false
>
["PMID", "Title", "Authors"]
#Ash.Changeset<
domain: Galenic.Categorization,
action_type: :create,
action: :create,
attributes: %{},
relationships: %{},
errors: [
%Ash.Error.Invalid.NoSuchInput{
calculation: nil,
resource: Galenic.Categorization.Request,
action: :create,
input: :columns,
inputs: MapSet.new([]),
did_you_mean: [],
splode: nil,
bread_crumbs: [],
vars: [],
path: [],
stacktrace: #Splode.Stacktrace<>,
class: :invalid
}
],
data: %Galenic.Categorization.Request{
id: nil,
columns: nil,
__meta__: #Ecto.Schema.Metadata
},
valid?: false
>
I've tried rewriting the create action many different ways and they all yield the same NoSuchInput error
Solution:
your create action doesn't accept the columns attribute
Jump to solution
4 Replies
Solution
sevenseacat
sevenseacat3mo ago
your create action doesn't accept the columns attribute
Boris - BackedBy
Boris - BackedByOP3mo ago
I thought public attributes were all accepted by default create actions?
sevenseacat
sevenseacat3mo ago
they can, if you declare create: :* in the defaults list (this behaviour will be deprecated in the future, in favor of explicitly listing accepted attributes) by default they don't accept anything
Boris - BackedBy
Boris - BackedByOP3mo ago
That fixed it. Thank you for the solution and explanation!

Did you find this page helpful?