Ash FrameworkAF
Ash Framework6mo ago
8 replies
Boris - BackedBy

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
...


   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
>


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
Was this page helpful?