tfwright / live_admin

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

Error when not using prefix - function nil.all/2 is undefined #64

Closed Rio517 closed 10 months ago

Rio517 commented 10 months ago

After generating an empty Phoenix app, generating a single resource, and adding live_admin, I get the following error.

[error] GenServer #PID<0.768.0> terminating
** (UndefinedFunctionError) function nil.all/2 is undefined
    nil.all(#Ecto.Query<from p0 in LiveAdminIssue.Posts.Post, order_by: [asc: p0.id], limit: 10, offset: ^0>, [prefix: nil])
    (live_admin 0.10.1) lib/live_admin/resource.ex:233: LiveAdmin.Resource.build_list/3
    (live_admin 0.10.1) lib/live_admin/components/resource/index.ex:22: LiveAdmin.Components.Container.Index.update/2
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/utils.ex:487: Phoenix.LiveView.Utils.maybe_call_update!/3
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/diff.ex:653: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (stdlib 4.3) maps.erl:411: :maps.fold_1/3
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/diff.ex:629: Phoenix.LiveView.Diff.render_pending_components/6
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:833: Phoenix.LiveView.Channel.render_diff/3
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:469: Phoenix.LiveView.Channel.mount_handle_params_result/3
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:1043: Phoenix.LiveView.Channel.verified_mount/8
    (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:59: Phoenix.LiveView.Channel.handle_info/2
    (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
    (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {Phoenix.Channel, %{"params" => %{"_csrf_token" => "USg1JhFiWSNWbxAnBnc2QyZCdQYtPEMFfOMmB7ksc_FmaAoti88Bl_zT", "_mounts" => 0}, "session" => "SFMyNTY.g2gDaAJhBXQAAAAIZAACaWRtAAAAFHBoeC1GM3Zmbk90MGwzQW9FUUxEZAAMbGl2ZV9zZXNzaW9uaAJkABRsaXZlX2FkbWluXy9teV9hZG1pbm4IAK_Omak333sXZAAKcGFyZW50X3BpZGQAA25pbGQACHJvb3RfcGlkZAADbmlsZAAJcm9vdF92aWV3ZAAlRWxpeGlyLkxpdmVBZG1pbi5Db21wb25lbnRzLkNvbnRhaW5lcmQABnJvdXRlcmQAH0VsaXhpci5MaXZlQWRtaW5Jc3N1ZVdlYi5Sb3V0ZXJkAAdzZXNzaW9udAAAAAZtAAAACWJhc2VfcGF0aG0AAAAJL215X2FkbWlubQAAAApjb21wb25lbnRzdAAAAAdkAARlZGl0ZAAqRWxpeGlyLkxpdmVBZG1pbi5Db21wb25lbnRzLkNvbnRhaW5lci5Gb3JtZAAEaG9tZWQAKEVsaXhpci5MaXZlQWRtaW4uQ29tcG9uZW50cy5Ib21lLkNvbnRlbnRkAARsaXN0ZAArRWxpeGlyLkxpdmVBZG1pbi5Db21wb25lbnRzLkNvbnRhaW5lci5JbmRleGQAA25hdmQAH0VsaXhpci5MaXZlQWRtaW4uQ29tcG9uZW50cy5OYXZkAANuZXdkACpFbGl4aXIuTGl2ZUFkbWluLkNvbXBvbmVudHMuQ29udGFpbmVyLkZvcm1kAAdzZXNzaW9uZAArRWxpeGlyLkxpdmVBZG1pbi5Db21wb25lbnRzLlNlc3Npb24uQ29udGVudGQABHZpZXdkACpFbGl4aXIuTGl2ZUFkbWluLkNvbXBvbmVudHMuQ29udGFpbmVyLlZpZXdtAAAACG9uX21vdW50ZAADbmlsbQAAAARyZXBvZAADbmlsbQAAAApzZXNzaW9uX2lkbQAAACQ5OWExZTk4Mi03ODgzLTQwMWYtOTA4MS0xYzYxNmIzOGIyZDFtAAAABXRpdGxlbQAAAAlMaXZlQWRtaW5kAAR2aWV3ZAAlRWxpeGlyLkxpdmVBZG1pbi5Db21wb25lbnRzLkNvbnRhaW5lcm4GAPEEgP6JAWIAAVGA.N94LdIa2duq87LJ1yga9XaB1d90IuFA9jROC8oWcKq8", "static" => "SFMyNTY.g2gDaAJhBXQAAAADZAAKYXNzaWduX25ld2pkAAVmbGFzaHQAAAAAZAACaWRtAAAAFHBoeC1GM3Zmbk90MGwzQW9FUUxEbgYA8gSA_okBYgABUYA.uDF11JrVTwNu5b3-QixRmXUnRCL9WumVkRpVQT5CW1Y", "url" => "http://localhost:4000/my_admin/posts"}, {#PID<0.761.0>, #Reference<0.2831961241.2145386497.34039>}, %Phoenix.Socket{assigns: %{}, channel: Phoenix.LiveView.Channel, channel_pid: nil, endpoint: LiveAdminIssueWeb.Endpoint, handler: Phoenix.LiveView.Socket, id: "users_sessions:yQS76IvwFkSKDoIUfXMVNSYYGantJAK7jA2jp2T0vSw=", joined: false, join_ref: "4", private: %{connect_info: %{session: %{"_csrf_token" => "7gxKSU2P50VJg6Y7OzMDAc9Q", "live_socket_id" => "users_sessions:yQS76IvwFkSKDoIUfXMVNSYYGantJAK7jA2jp2T0vSw=", "user_token" => <<201, 4, 187, 232, 139, 240, 22, 68, 138, 14, 130, 20, 125, 115, 21, 53, 38, 24, 25, 169, 237, 36, 2, 187, 140, 13, 163, 167, 100, 244, 189, 44>>}}}, pubsub_server: LiveAdminIssue.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "lv:phx-F3vfnOt0l3AoEQLD", transport: :websocket, transport_pid: #PID<0.761.0>}}
State: #Reference<0.2831961241.2145386497.34041>
[error] an exception was raised:
    ** (UndefinedFunctionError) function nil.all/2 is undefined
        nil.all(#Ecto.Query<from p0 in LiveAdminIssue.Posts.Post, order_by: [asc: p0.id], limit: 10, offset: ^0>, [prefix: nil])
        (live_admin 0.10.1) lib/live_admin/resource.ex:233: LiveAdmin.Resource.build_list/3
        (live_admin 0.10.1) lib/live_admin/components/resource/index.ex:22: LiveAdmin.Components.Container.Index.update/2
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/utils.ex:487: Phoenix.LiveView.Utils.maybe_call_update!/3
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/diff.ex:653: anonymous fn/5 in Phoenix.LiveView.Diff.render_pending_components/6
        (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (stdlib 4.3) maps.erl:411: :maps.fold_1/3
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/diff.ex:629: Phoenix.LiveView.Diff.render_pending_components/6
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:833: Phoenix.LiveView.Channel.render_diff/3
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:469: Phoenix.LiveView.Channel.mount_handle_params_result/3
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:1043: Phoenix.LiveView.Channel.verified_mount/8
        (phoenix_live_view 0.19.5) lib/phoenix_live_view/channel.ex:59: Phoenix.LiveView.Channel.handle_info/2
        (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
        (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
        (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

You can see the example app here and how I installed live_admin in the associated git commit.

I was setting this up to investigate https://github.com/tfwright/live_admin/issues/63.

tfwright commented 10 months ago

Thanks for setting up the example app. I'll take a look. What steps did you take prior to generating the error?

Rio517 commented 10 months ago

I only logged in, created a post, and tried to visit the my_admin/posts page.

tfwright commented 10 months ago

Have to admit you got me with this one! https://github.com/Rio517/live_admin_issue/pull/1 took me way longer than it should have to spot that. that will teach me not to validate config!

tfwright commented 10 months ago

998ff7a

tfwright commented 10 months ago

While I had the app running I went ahead and tested the checkbox UX and it seemed to work:

https://github.com/tfwright/live_admin/assets/501/41d60f35-33c5-4172-9f99-b998f8a6587f

Rio517 commented 10 months ago

Thanks so much!

tfwright commented 10 months ago

@Rio517 are you still seeing the the buggy behavior on this app?

Rio517 commented 10 months ago

@tfwright Sorry for the slow response: I had a bad ear infection. And thanks so much for checking the app! The checkbox app does work until you add an embeds_many. I added a commit to demonstrate the problem, also seen in this video.

I'll add this info to the relevant issue: https://github.com/tfwright/live_admin/issues/63.

https://github.com/tfwright/live_admin/assets/14241/8714fc1d-2f63-4dcc-a1e0-f109dc373a8c