JimmyCarterSon

JimmyCarterSon

Troubleshooting Code: (KeyError) key :changeset not found

I am following this tutorial . I have followed carefully correcting errors as I go. The app allows you to create a blog post and add comments if you so choose. When I click show Posts, this error I am getting:

[error] #PID<0.581.0> running BlogAppWeb.Endpoint (connection #PID<0.552.0>, stream id 6) terminated
Server: localhost:4000 (http)
Request: GET /posts/1
** (exit) an exception was raised:
    ** (KeyError) key :changeset not found in: %{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{layout: {BlogAppWeb.LayoutView, "app.html"}, post: %BlogApp.Posts.Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">, body: "This here is my duck named Mr.Lump My friend Anum is here.", comments: #Ecto.Association.NotLoaded<association :comments is not loaded>, id: 1, inserted_at: ~N[2022-03-17 17:38:18], title: "Look at my Duck, his name is Lump", updated_at: ~N[2022-03-18 17:45:40]}}, body_params: %{}, cookies: %{"_blog_app_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYSjBybkJSX2U0ZHVyalNoLVkzeHhCdlRt.wbQhUfCTv_8d1yKDupYSNN_ewiSgDMVBypamZHRIP1o", "_live_view_todos_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYWWJ1XzE5MnJSSkV6OVl3eVl0cUpvM2pN.NJYDbH-n7JlaQFMHL2_x-T2zhhvyYD6XBmo8GequxP8"}, halted: false, host: "localhost", method: "GET", owner: #PID<0.581.0>, params: %{"id" => "1"}, path_info: ["posts", "1"], path_params: %{"id" => "1"}, port: 4000, private: %{BlogAppWeb.Router => {[], %{Plug.Swoosh.MailboxPreview => ["mailbox"]}}, :before_send => [#Function<0.16477574/1 in Plug.CSRFProtection.call/2>, #Function<2.17183421/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.77458138/1 in Plug.Session.before_send/2>, #Function<0.23023616/1 in Plug.Telemetry.call/2>, #Function<1.46227650/1 in Phoenix.LiveReloader.before_send_inject_reloader/3>], :phoenix_action => :show, :phoenix_controller => BlogAppWeb.PostController, :phoenix_endpoint => BlogAppWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {BlogAppWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_root_layout => {BlogAppWeb.LayoutView, :root}, :phoenix_router => BlogAppWeb.Router, :phoenix_template => "show.html", :phoenix_view => BlogAppWeb.PostView, :plug_session => %{"_csrf_token" => "J0rnBR_e4durjSh-Y3xxBvTm"}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{"_blog_app_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYSjBybkJSX2U0ZHVyalNoLVkzeHhCdlRt.wbQhUfCTv_8d1yKDupYSNN_ewiSgDMVBypamZHRIP1o", "_live_view_todos_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYWWJ1XzE5MnJSSkV6OVl3eVl0cUpvM2pN.NJYDbH-n7JlaQFMHL2_x-T2zhhvyYD6XBmo8GequxP8"}, req_headers: [{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-US,en;q=0.9"}, {"connection", "keep-alive"}, {"cookie", "_live_view_todos_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYWWJ1XzE5MnJSSkV6OVl3eVl0cUpvM2pN.NJYDbH-n7JlaQFMHL2_x-T2zhhvyYD6XBmo8GequxP8; _blog_app_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYSjBybkJSX2U0ZHVyalNoLVkzeHhCdlRt.wbQhUfCTv_8d1yKDupYSNN_ewiSgDMVBypamZHRIP1o"}, {"host", "localhost:4000"}, {"referer", "http://localhost:4000/posts"}, {"sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\""}, {"sec-ch-ua-mobile", "?0"}, {"sec-ch-ua-platform", "\"macOS\""}, {"sec-fetch-dest", "document"}, {"sec-fetch-mode", "navigate"}, {"sec-fetch-site", "same-origin"}, {"sec-fetch-user", "?1"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"}], request_path: "/posts/1", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "Ft5qQ01M_yh3344AAAAE"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}, {"x-download-options", "noopen"}, {"x-permitted-cross-domain-policies", "none"}, {"cross-origin-window-policy", "deny"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: nil}, post: %BlogApp.Posts.Post{__meta__: #Ecto.Schema.Metadata<:loaded, "posts">, body: "This here is my duck named Mr.Lump My friend Anum is here.", comments: #Ecto.Association.NotLoaded<association :comments is not loaded>, id: 1, inserted_at: ~N[2022-03-17 17:38:18], title: "Look at my Duck, his name is Lump", updated_at: ~N[2022-03-18 17:45:40]}}
        (blog_app 0.1.0) lib/blog_app_web/templates/post/show.html.heex:19: anonymous fn/2 in BlogAppWeb.PostView."show.html"/1
        (phoenix_live_view 0.17.7) lib/phoenix_live_view/engine.ex:124: Phoenix.HTML.Safe.Phoenix.LiveView.Rendered.to_iodata/1
        (phoenix_live_view 0.17.7) lib/phoenix_live_view/engine.ex:140: Phoenix.HTML.Safe.Phoenix.LiveView.Rendered.to_iodata/3
        (phoenix 1.6.6) lib/phoenix/controller.ex:772: Phoenix.Controller.render_and_send/4
        (blog_app 0.1.0) lib/blog_app_web/controllers/post_controller.ex:1: BlogAppWeb.PostController.action/2
        (blog_app 0.1.0) lib/blog_app_web/controllers/post_controller.ex:1: BlogAppWeb.PostController.phoenix_controller_pipeline/2
        (phoenix 1.6.6) lib/phoenix/router.ex:355: Phoenix.Router.__call__/2
        (blog_app 0.1.0) lib/blog_app_web/endpoint.ex:1: BlogAppWeb.Endpoint.plug_builder_call/2
        (blog_app 0.1.0) lib/plug/debugger.ex:136: BlogAppWeb.Endpoint."call (overridable 3)"/2
        (blog_app 0.1.0) lib/blog_app_web/endpoint.ex:1: BlogAppWeb.Endpoint.call/2
        (phoenix 1.6.6) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.9.0) /Users/shansiddiqui/Desktop/blog_app/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.9.0) /Users/shansiddiqui/Desktop/blog_app/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
        (cowboy 2.9.0) /Users/shansiddiqui/Desktop/blog_app/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
        (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

This error is coming when I Get Posts, also I cant show posts? Any Idea to go around this

Marked As Solved

dimitarvp

dimitarvp

Since that’s an exercise I believe there’s no harm if you post it publicly on GitHub and link it here. Maybe the tutorial is stale, maybe it made a small error (or maybe you did).

In any case yeah, there’s no Ecto.Changeset in the object that’s being consulted nor there should be so there’s code that’s looking at the wrong place.

Also Liked

JimmyCarterSon

JimmyCarterSon

I actually did find the answer I combed the code and found that there were two functions. I am running into a new error that is confusing me!

Now I have a new error compile error. The function does exist but, cannot be found.Do you think it was to do with the alias (referencing) the component?

Error:

== Compilation error in file lib/blog_app_web/views/post_view.ex ==
** (CompileError) lib/blog_app_web/views/post_view.ex:2: module BlogWeb is not loaded and could not be found
    (elixir 1.13.3) expanding macro: Kernel.use/2
    lib/blog_app_web/views/post_view.ex:2: BlogWeb.PostView (module)

Post_view.ex:

defmodule BlogWeb.PostView do
	use BlogWeb, :view
	alias BlogApp.Posts

	def get_comments_count(post_id) do
		Posts.get_number_of_comments(post_id)
	end
end
dimitarvp

dimitarvp

Look for which module in your app defines a view function e.g.

defmodule YourModule do
  dev view do
    # ...
  end
end

In your case it should be BlogWeb but who knows, maybe it’s another one.

Popular Backend topics Top

wolf4earth
At work we plan to replace a totally overkill Kafka instance with a combination of SNS and SQS. I don’t want to get into a discussion on ...
New
New
GermaVinsmoke
Reading Programming Elixir 1.6 book, I’ve completed part 1 of the book. Now I’m thinking of reading Elixir in Action. What do you all sug...
New
Ookma-Kyi
I am learning Elixir at the moment but am finding it difficult to learn. The issue is there aren’t any good tutorial sites out there when...
New
Fl4m3Ph03n1x
Background I have a personal project that is an elixir desktop application for PC Windows. It works pretty well, but now I want to give i...
New
Fl4m3Ph03n1x
Background I am moving towards defined data structures in my application, and I find that TypedStruct is quite useful. Questions Howeve...
New
Fl4m3Ph03n1x
Background I am a fan of dialyzer and friends (looking at Gradient) and I try to have sepcs in my code as much as I can. To this end, I a...
New
sona11
I wrote this code to calculate Fibonacci numbers by specifying the size. The results are correct, however the one thing that concerns me ...
New
pillaiindu
Currently reading the book “Programming Phoenix LiveView”. At the end of the Chapter 1, I’m trying to solve the guess game. If the user ...
New
pillaiindu
What is the difference between using :references and :belongs_to in the following command? bin/rails generate scaffold LineItem product:...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New