tfwright / live_admin

Low-config admin UI for Phoenix apps, built on LiveView
MIT License
248 stars 22 forks source link

[Bug] ** (UndefinedFunctionError) function nil.all/2 is undefined #100

Closed danieljaouen closed 5 months ago

danieljaouen commented 5 months ago

Describe the bug

The code:

defmodule DocumentStore.UsersAdmin do
  use LiveAdmin.Resource, schema: DocumentStore.Accounts.User
end

The bug:

[error] GenServer #PID<0.843.0> terminating
** (UndefinedFunctionError) function nil.all/2 is undefined
    nil.all(#Ecto.Query<from c0 in DocumentStore.Entities.Client, order_by: [asc: c0.id], limit: 10, offset: ^0, preload: [:user]>, [prefix: nil])
    (live_admin 0.11.4) lib/live_admin/resource.ex:235: LiveAdmin.Resource.build_list/4
    (live_admin 0.11.4) lib/live_admin/components/resource/index.ex:25: LiveAdmin.Components.Container.Index.update/2
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/utils.ex:498: Phoenix.LiveView.Utils.maybe_call_update!/3
    (elixir 1.16.0) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:681: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
    (telemetry 1.2.1) /Users/danieljaouen/src/document_store/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:676: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
    (stdlib 5.2) maps.erl:416: :maps.fold_1/4
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:635: Phoenix.LiveView.Diff.render_pending_components/6
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:953: anonymous fn/4 in Phoenix.LiveView.Channel.render_diff/3
    (telemetry 1.2.1) /Users/danieljaouen/src/document_store/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:948: Phoenix.LiveView.Channel.render_diff/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:575: Phoenix.LiveView.Channel.mount_handle_params_result/3
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:1169: Phoenix.LiveView.Channel.verified_mount/8
    (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:84: Phoenix.LiveView.Channel.handle_info/2
    (stdlib 5.2) gen_server.erl:1095: :gen_server.try_handle_info/3
    (stdlib 5.2) gen_server.erl:1183: :gen_server.handle_msg/6
    (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {Phoenix.Channel, %{"params" => %{"_csrf_token" => "clip", "_mounts" => 0}, "session" => "clip", "static" => "clip", "url" => "http://localhost:4000/admin/clients"}, {#PID<0.830.0>, #Reference<clip>}, %Phoenix.Socket{assigns: %{}, channel: Phoenix.LiveView.Channel, channel_pid: nil, endpoint: DocumentStoreWeb.Endpoint, handler: Phoenix.LiveView.Socket, id: "users_sessions:clip=", joined: false, join_ref: "4", private: %{connect_info: %{session: %{"_csrf_token" => "clip-clip", "live_socket_id" => "users_sessions:clip=", "user_token" => <<clip>>}}}, pubsub_server: DocumentStore.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "lv:phx-clip", transport: :websocket, transport_pid: #PID<clip>}}
State: #Reference<clip>
[error] an exception was raised:
    ** (UndefinedFunctionError) function nil.all/2 is undefined
        nil.all(#Ecto.Query<from c0 in DocumentStore.Entities.Client, order_by: [asc: c0.id], limit: 10, offset: ^0, preload: [:user]>, [prefix: nil])
        (live_admin 0.11.4) lib/live_admin/resource.ex:235: LiveAdmin.Resource.build_list/4
        (live_admin 0.11.4) lib/live_admin/components/resource/index.ex:25: LiveAdmin.Components.Container.Index.update/2
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/utils.ex:498: Phoenix.LiveView.Utils.maybe_call_update!/3
        (elixir 1.16.0) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:681: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
        (telemetry 1.2.1) /Users/danieljaouen/src/document_store/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:676: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
        (stdlib 5.2) maps.erl:416: :maps.fold_1/4
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:635: Phoenix.LiveView.Diff.render_pending_components/6
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:953: anonymous fn/4 in Phoenix.LiveView.Channel.render_diff/3
        (telemetry 1.2.1) /Users/danieljaouen/src/document_store/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:948: Phoenix.LiveView.Channel.render_diff/3
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:575: Phoenix.LiveView.Channel.mount_handle_params_result/3
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:1169: Phoenix.LiveView.Channel.verified_mount/8
        (phoenix_live_view 0.20.4) lib/phoenix_live_view/channel.ex:84: Phoenix.LiveView.Channel.handle_info/2
        (stdlib 5.2) gen_server.erl:1095: :gen_server.try_handle_info/3
        (stdlib 5.2) gen_server.erl:1183: :gen_server.handle_msg/6
        (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /manifest.json (DocumentStoreWeb.Router)
    (document_store 0.1.0) deps/phoenix/lib/phoenix/router.ex:541: DocumentStoreWeb.Router.call/2
    (document_store 0.1.0) lib/document_store_web/endpoint.ex:1: DocumentStoreWeb.Endpoint.plug_builder_call/2
    (document_store 0.1.0) deps/plug/lib/plug/debugger.ex:136: DocumentStoreWeb.Endpoint."call (overridable 3)"/2
    (document_store 0.1.0) lib/document_store_web/endpoint.ex:1: DocumentStoreWeb.Endpoint.call/2
    (phoenix 1.7.11) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
    (bandit 1.2.0) lib/bandit/pipeline.ex:101: Bandit.Pipeline.call_plug/2
    (bandit 1.2.0) lib/bandit/pipeline.ex:22: Bandit.Pipeline.run/6
    (bandit 1.2.0) lib/bandit/http1/handler.ex:33: Bandit.HTTP1.Handler.handle_data/3
    (bandit 1.2.0) lib/bandit/delegating_handler.ex:18: Bandit.DelegatingHandler.handle_data/3
    (bandit 1.2.0) /Users/danieljaouen/src/document_store/deps/thousand_island/lib/thousand_island/handler.ex:379: Bandit.DelegatingHandler.handle_info/2
    (stdlib 5.2) gen_server.erl:1095: :gen_server.try_handle_info/3
    (stdlib 5.2) gen_server.erl:1183: :gen_server.handle_msg/6
    (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Not sure what the problem is here. Any help?

tfwright commented 5 months ago

It looks like it is not able to find a configured Ecto repo.

Can you double check that you completed the last step of the installation instructions that specifies the repo in your app config? e.g. config :live_admin, ecto_repo: MyApp.Repo

danieljaouen commented 5 months ago

Yep. My config/runtime.exs has the following at the bottom of the file:

config :live_admin, ecto_repo: DocumentStore.Repo

tfwright commented 5 months ago

If you console into your app in the same environment you are getting the error and run Application.fetch_env(:live_admin) what is the output?

tfwright commented 5 months ago

Also what is the output of mix deps for live_admin

danieljaouen commented 5 months ago

I figured it out. I had the config call inside the if statement in runtime.exs that checks if it's running in the prod environment. Sorry for the mix-up!

tfwright commented 5 months ago

No problem, glad you figured it out!