mikesax

mikesax

Ash.Error.Invalid.NoSuchInput on create

I’m starting to play with Ash, because I feel it will give me the DRYness of Rails and the clarity of Elixir & Phoenix. I roughly followed the Postgres how-to guide on the Ash framework website but I’m getting an error that I can’t explain, running this code:

Marketing.Lead
|> Ash.Changeset.for_create(:create, %{email: "mike@example.com", farmer: true})
|> Ash.create!()

This yields an error:

  (elixir 1.16.2) lib/process.ex:860: Process.info/2
  (ash 3.1.3) lib/ash/error/invalid/no_such_input.ex:5: Ash.Error.Invalid.NoSuchInput."exception (overridable 2)"/1
  (ash 3.1.3) lib/ash/changeset/changeset.ex:2034: anonymous fn/4 in Ash.Changeset.cast_params/4
   ...

I suspect it has something to do with the definition of my resource. Any ideas on how to figure out what’s causing this? Thank you for your time!

defmodule Marketing.Lead do
  use Ash.Resource, domain: Marketing, data_layer: AshPostgres.DataLayer

  postgres do
    table "leads"
    repo Muck.Repo
  end

  actions do
    defaults [:read]

    create :create
  end

  attributes do
    uuid_primary_key :id

    attribute :email, :string do
      allow_nil? false
    end

    attribute :farmer, :boolean do
      allow_nil? false
      default false
    end

    attribute :writer, :boolean do
      allow_nil? false
      default false
    end

    attribute :academic, :boolean do
      allow_nil? false
      default false
    end

    attribute :other, :string
  end
end

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

By default, an action does not accept any attributes as inputs. To resolve this, you have two options:

  1. Set an explicit accept list. this is the simplest
create :create do
  accept [:email, :farmer]
end
  1. Use :*, which means all public attributes

For example:

create :create do
  accept :*
end

...

attribute :email, :string do
  allow_nil? false
  public? true
end

attribute :farmer, :boolean do
  allow_nil? false
  public? true
end

This option is a bit more complex because public? affects other things like visibility over external APIs, etc.

Also Liked

zachdaniel

zachdaniel

Creator of Ash

Yeah, I think updating the docs there is likely the best way to go, even just to indicate that we’ll be accepting things later, like

create :create do
  accept []
end

instead of just create :create would help with some of the confusion. I think we want to keep it to NoSuchInput because the type of error is used by things like api extensions to show error messages, and we want to make sure that its not possible for API extensions to leak internal resource details.

but, we can add “hints” that are in the error message on NoSuchInput, like “an attribute with this name exists, but is not accepted by the action. Perhaps you need to add it to the accept list of the action?”

If you could open issues or PRs for these two improvements, that would be wonderful :bowing_man:

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement