Wondering if this Ecto validation error is a legitimate issue

I spent some time being puzzled today. To simplify, the reason was that I wanted this code:

defmodule Eecrit.User do
  use Eecrit.Web, :model
  schema "users" do
    field :display_name, :string

  def cs_this_works(starting_value, additions) do
    cast(starting_value, additions, ~w(display_name), [])      # This line will be wrong below.

… but what I actually typed was this:

  def cs_this_fails(starting_value, additions) do
    cast(starting_value, additions, ~w(display_name_TYPO), [])

Had I not made the typo, the result of passing in bad form parameters would have been:

iex(1)> User.cs_this_works(%User{}, %{})
#Ecto.Changeset<action: nil, changes: %{},
 errors: [display_name: {"can't be blank", []}], data: #Eecrit.User<>,
 valid?: false>

As it was, though, the result was this:

iex(2)> User.cs_this_fails(%User{}, %{})
** (ArgumentError) argument error
             :erlang.binary_to_existing_atom("display_name_typo", :utf8)
      (ecto) lib/ecto/changeset.ex:422: Ecto.Changeset.cast_key/1
      (ecto) lib/ecto/changeset.ex:390: Ecto.Changeset.process_param/6
    (elixir) lib/enum.ex:1246: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
      (ecto) lib/ecto/changeset.ex:371: Ecto.Changeset.do_cast/6

As an Elixir/Phoenix novice, it took me a long time to figure this out. In my previous world (Clojure), asking for a fix would’ve been pointless. As a newbie to Elixir, is it reasonable to open an issue?


Yes, I believe we can give a better error message there. Could you please open an issue on ecto’s github?