ITM007

ITM007

Phoenix Gen Auth Error on NixOS

Phoenix 1.7

I am new to elixir and am working through the Elixir Phoenix Docs, while following this https://hexdocs.pm/phoenix/mix_phx_gen_auth.html. But I am getting an error when running the tests once the auth is generated. This is done with postgres, I get the same error when using sqlite.

Steps to reproduce:

  • Create new phx project
  • Install dependencies and create database
  • mix test (5 or 5 test pass)
  • mix phx.gen.auth Accounts User users
  • mix deps.get
  • mix ecto.setup
  • mix test (30 tests fail of 128)

Error:

 29) test update email form renders errors with invalid data (phx-change) (MyprojectWeb.UserSettingsLiveTest)
     test/myproject_web/live/user_settings_live_test.exs:52
     ** (KeyError) key :name not found in: %{
       __changed__: nil,
       __given__: %{
         __changed__: nil,
         field: %Phoenix.HTML.FormField{
           id: "user_email",
           name: "user[email]",
           errors: [],
           field: :email,
           form: %Phoenix.HTML.Form{
             source: #Ecto.Changeset<
               action: nil,
               changes: %{},
               errors: [email: {"did not change", []}],
               data: #Myproject.Accounts.User<>,
               valid?: false
             >,
             impl: Phoenix.HTML.FormData.Ecto.Changeset,
             id: "user",
             name: "user",
             data: #Myproject.Accounts.User<
               __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
               id: 58,
               email: "user-576460752303416959@example.com",
               confirmed_at: nil,
               inserted_at: ~N[2024-05-05 18:24:05],
               updated_at: ~N[2024-05-05 18:24:05],
               ...
             >,
             hidden: [id: 58],
             params: %{},
             errors: [],
             options: [method: "put"],
             index: nil,
             action: nil
           },
           value: "user-576460752303416959@example.com"
         },
         label: "Email",
         type: "email"
       },
       field: %Phoenix.HTML.FormField{
         id: "user_email",
         name: "user[email]",
         errors: [],
         field: :email,
         form: %Phoenix.HTML.Form{
           source: #Ecto.Changeset<
             action: nil,
             changes: %{},
             errors: [email: {"did not change", []}],
             data: #Myproject.Accounts.User<>,
             valid?: false
           >,
           impl: Phoenix.HTML.FormData.Ecto.Changeset,
           id: "user",
           name: "user",
           data: #Myproject.Accounts.User<
             __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
             id: 58,
             email: "user-576460752303416959@example.com",
             confirmed_at: nil,
             inserted_at: ~N[2024-05-05 18:24:05],
             updated_at: ~N[2024-05-05 18:24:05],
             ...
           >,
           hidden: [id: 58],
           params: %{},
           errors: [],
           options: [method: "put"],
           index: nil,
           action: nil
         },
         value: "user-576460752303416959@example.com"
       },
       inner_block: [],
       label: "Email",
       multiple: false,
       prompt: nil,
       rest: %{required: true},
       type: "email"
     }
     stacktrace:
       (myproject 0.1.0) lib/myproject_web/components/core_components.ex:350: anonymous fn/2 in MyprojectWeb.CoreComponents."input (overridable 1)"/1
       (myproject 0.1.0) /home/itm/Code/myproject/lib/myproject_web/live/user_settings_live.ex:21: MyprojectWeb.UserSettingsLive.render/1
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3



 30) test update email form renders errors with invalid data (phx-submit) (MyprojectWeb.UserSettingsLiveTest)
     test/myproject_web/live/user_settings_live_test.exs:68
     ** (KeyError) key :name not found in: %{
       __changed__: nil,
       __given__: %{
         __changed__: nil,
         field: %Phoenix.HTML.FormField{
           id: "user_email",
           name: "user[email]",
           errors: [],
           field: :email,
           form: %Phoenix.HTML.Form{
             source: #Ecto.Changeset<
               action: nil,
               changes: %{},
               errors: [email: {"did not change", []}],
               data: #Myproject.Accounts.User<>,
               valid?: false
             >,
             impl: Phoenix.HTML.FormData.Ecto.Changeset,
             id: "user",
             name: "user",
             data: #Myproject.Accounts.User<
               __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
               id: 59,
               email: "user-576460752303418878@example.com",
               confirmed_at: nil,
               inserted_at: ~N[2024-05-05 18:24:05],
               updated_at: ~N[2024-05-05 18:24:05],
               ...
             >,
             hidden: [id: 59],
             params: %{},
             errors: [],
             options: [method: "put"],
             index: nil,
             action: nil
           },
           value: "user-576460752303418878@example.com"
         },
         label: "Email",
         type: "email"
       },
       field: %Phoenix.HTML.FormField{
         id: "user_email",
         name: "user[email]",
         errors: [],
         field: :email,
         form: %Phoenix.HTML.Form{
           source: #Ecto.Changeset<
             action: nil,
             changes: %{},
             errors: [email: {"did not change", []}],
             data: #Myproject.Accounts.User<>,
             valid?: false
           >,
           impl: Phoenix.HTML.FormData.Ecto.Changeset,
           id: "user",
           name: "user",
           data: #Myproject.Accounts.User<
             __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
             id: 59,
             email: "user-576460752303418878@example.com",
             confirmed_at: nil,
             inserted_at: ~N[2024-05-05 18:24:05],
             updated_at: ~N[2024-05-05 18:24:05],
             ...
           >,
           hidden: [id: 59],
           params: %{},
           errors: [],
           options: [method: "put"],
           index: nil,
           action: nil
         },
         value: "user-576460752303418878@example.com"
       },
       inner_block: [],
       label: "Email",
       multiple: false,
       prompt: nil,
       rest: %{required: true},
       type: "email"
     }
     stacktrace:
       (myproject 0.1.0) lib/myproject_web/components/core_components.ex:350: anonymous fn/2 in MyprojectWeb.CoreComponents."input (overridable 1)"/1
       (myproject 0.1.0) /home/itm/Code/myproject/lib/myproject_web/live/user_settings_live.ex:21: MyprojectWeb.UserSettingsLive.render/1
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
       (phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
       (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3

.......................................................
Finished in 0.7 seconds (0.5s async, 0.2s sync)
128 tests, 30 failures

Randomized with seed 825518

Dependencies:

 defp deps do
   25    ╎ [
   24    ╎ ╎ {:bcrypt_elixir, "~> 3.0"},
   23    ╎ ╎ {:phoenix, "~> 1.7.0-rc.1", override: true},
   22    ╎ ╎ {:phoenix_ecto, "~> 4.4"},
   21    ╎ ╎ {:ecto_sql, "~> 3.6"},
   20    ╎ ╎ {:postgrex, ">= 0.0.0"},
   19    ╎ ╎ {:phoenix_html, "~> 3.0"},
   18    ╎ ╎ {:phoenix_live_reload, "~> 1.2", only: :dev},
   17    ╎ ╎ {:phoenix_live_view, "~> 0.18.3"},
   16    ╎ ╎ {:heroicons, "~> 0.5"},
   15    ╎ ╎ {:floki, ">= 0.30.0", only: :test},
   14    ╎ ╎ {:phoenix_live_dashboard, "~> 0.7.2"},
   13    ╎ ╎ {:esbuild, "~> 0.5", runtime: Mix.env() == :dev},
   12    ╎ ╎ {:tailwind, "~> 0.1.8", runtime: Mix.env() == :dev},
   11    ╎ ╎ {:swoosh, "~> 1.3"},
   10    ╎ ╎ {:finch, "~> 0.13"},
    9    ╎ ╎ {:telemetry_metrics, "~> 0.6"},
    8    ╎ ╎ {:telemetry_poller, "~> 1.0"},
    7    ╎ ╎ {:gettext, "~> 0.20"},
    6    ╎ ╎ {:jason, "~> 1.2"},
    5    ╎ ╎ {:plug_cowboy, "~> 2.5"}
    4    ╎ ]
    3    end

I am using NixOS, so I am guessing I am missing a dependency. Or maybe I may just not be following the documentation correctly? Any help would be appreciated.

Thanks! :smiley:

Marked As Solved

josevalim

josevalim

Creator of Elixir

In particular, make sure to run mix archive.install hex phx_new to get the latest.

Also Liked

al2o3cr

al2o3cr

Make 100% sure that the various pieces of Phoenix are on the correct version.

The error you’re seeing is what I’d expect if an old core_components.ex was being used with a too-new version of phx.gen.auth:

See also previous discussion: KeyError at GET /users/register key :name not found in: %{ - #7 by experimentix

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement