wlminimal
Hi I am using drab to update chart js in a page
here is defhandler
defhandler show_dashboard_stats(socket, sender) do
order_id = sender.params["campaign_id"]
user_id = socket.assigns.current_user_id
order = Sales.get_order_by_id(order_id, user_id)
message_status = Messenger.get_all_message_status(order_id)
total_sent = Enum.count(message_status)
deilvered_count = Analytics.get_delivered_message_status_count(message_status)
undelivered_count = Analytics.get_undelivered_message_status_count(message_status)
bitly = Bitly.get_bilty_by_order_id(order_id)
total_clicks = Analytics.load_clicks(bitly)
poke socket,
total_sent: total_sent,
deilvered_count: deilvered_count,
undelivered_count: undelivered_count,
total_clicks: total_clicks,
recent_order: order
socket |> exec_js!("DashboardChart.update()")
end
and here is error message.
** (KeyError) key :current_user not found in: %{}
(texting) lib/texting_web/templates/dashboard/dashboard/index.html.drab:164: TextingWeb.Dashboard.DashboardView."index.html"/1
(phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/view.ex:339: Phoenix.View.render_to_string/3
(drab) lib/drab/live.ex:662: Drab.Live.rerender_template/4
(drab) lib/drab/live.ex:617: Drab.Live.process_poke/9
(texting) lib/texting_web/commanders/dashboard/dashboard_commander.ex:17: TextingWeb.Dashboard.DashboardCommander.show_dashboard_stats/2
(drab) lib/drab.ex:323: anonymous fn/7 in Drab.handle_event/6
And I don’t understand
** (KeyError) key :current_user not found in: %{}
in my app.html.eex I passed current_user id to drab like this
<%= Drab.Client.run(@conn, [current_user_id: @conn.assigns.current_user.id, order_id: @conn.assigns.recipients.id]) %>
So I inspected socket assigns in defhandler
then it shows correct user id.
So where does this error (KeyError) key :current_user not found in: %{} come from?
Almost same defhandler works in other page.
what is the possible cause?
Thanks
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
grych
I would start checking with this file, line 164. Can you show it?
wlminimal
sure.
<div class=“stats”>
<i class=“material-icons”>access_time</i> You have <%= @conn.assigns.current_user.credits %> credits.
</div>
I assign :current_user using Plug in load_user.ex
in router.ex
grych
So this is a
conncase again.Drab uses castrated version of
conn, as it could be very heavy, especially when you keep a lot of data in assigns. See this issue for a reference. Drab creates it’s own version of conn, which by default copy only the few fields inprivate.This behaviour is documented here. What you need is just to add something like
:assigns => :current_userto:live_conn_pass_throughconfig.I know it is quite counter-intuitive, but I didn’t find any solution to change this, or at least tell user it is using the castrated conn version. Anyone?
wlminimal
OK. I did it exactly you and doc said.
and then I got this error
`
`
What am I missing?
grych
Ok, still I need way more information. On which line of code the error occurs and what’s there? What exactly you’ve set as
:live_conn_pass_throughin the config? What is %Texting.Account.User{}?wlminimal
%Texting.Account.User{} is a user struct that I assign to conn as current_user.
grych
OK, what about which line of code the error occurs and what’s there?
wlminimal
That is tricky. I thought errors from <%= @conn.assigns.current_user.credits %>
So I comment out that lines but it got me same errors.
And after set :live_conn_pass_through, drab in other page gives me an same error. (it worked ok before set :live_conn_pass) and some other page it shows me errors like this
OvermindDL1
Wait what?
How is this being hit:
https://github.com/grych/drab/blob/master/lib/drab/live/assign.ex#L66
When this is before it:
https://github.com/grych/drab/blob/master/lib/drab/live/assign.ex#L62
And that checks if it is a struct?! o.O
grych
Oh, exactly. How come?
This part of code hasn’t been changed for a while.
@wlminimal, please report it as a bug in github, I need to do more research.