kaffy icon indicating copy to clipboard operation
kaffy copied to clipboard

[BUG] String.binary_to_existing_atom

Open EdBondArcher opened this issue 5 years ago • 8 comments

Versions Used Kaffy: 0.9.0 Phoenix: 1.5 Elixir: 1.10.3

What's actually happening? When a string that isn't already an atom is tried to be converted it barfs.

Request: GET /admin/accounts/user/1 ** (exit) an exception was raised: ** (ArgumentError) argument error :erlang.binary_to_existing_atom("accounts", :utf8) (kaffy 0.9.0) lib/kaffy/utils.ex:339: Kaffy.Utils.convert_to_atom/1 (kaffy 0.9.0) lib/kaffy/utils.ex:335: Kaffy.Utils.convert_to_atoms/2 (kaffy 0.9.0) lib/kaffy/utils.ex:194: Kaffy.Utils.get_resource/3

What should happen instead? Maybe don't require it to be an existing atom?

EdBondArcher avatar Aug 07 '20 18:08 EdBondArcher

Hey @EdBondRSA

We're using String.to_existing_atom/1 because contexts/schemas names should already exist as atoms by default. If they don't, there's something wrong in the setup.

Are you manually defining resources in the config.exs file? This error could happen if you are manually defining resources and you either mistyped the context names or you don't have :accounts as a listed resource. It could also be that you visited the URL /admin/accounts/user/1 directly without going to /admin/ first for some reason. These are the only known issues for this particular error.

Could you please share your Kaffy configs so I have a better understanding of what's going on?

aesmail avatar Aug 07 '20 19:08 aesmail

:wave:

In local development it works fine, doing the release mode is what is coming up funky.

So:

config :kaffy,
  otp_app: :abc,
  ecto_repo: Abc.Repo,
  router: AbcWeb.Router

I went to admin -> clickd on the context -> clicked on the account row. We are also behind a load balancer and the nodes are not clusterd.

Also on the live view dashboard I don't see the atom list etc.

EdBondArcher avatar Aug 07 '20 19:08 EdBondArcher

Interesting. I'm not exactly sure of the root cause of this issue. I'd try to list resources manually and see if this fixes the problem. If you have a long list of schema/admin modules, you could start an iex session and write the following: Kaffy.Utils.full_resources(nil) This will output the list of your resources (contexts, schemas, admin modules, etc). You could copy the output and paste it in the config file, like:

config :kaffy,
  otp_app: :abc,
  ecto_repo: Abc.Repo,
  router: AbcWeb.Router,
  resources: # Kaffy.Utils.full_resources/1 output goes here

Let me know if this helps.

aesmail avatar Aug 07 '20 20:08 aesmail

once I get this deployed and tested I will let you know

EdBondArcher avatar Aug 07 '20 21:08 EdBondArcher

Manually specifying the resources fixes it for now, so it's a work around, yay! :clap:

EdBondArcher avatar Aug 08 '20 00:08 EdBondArcher

This is interesting. I'm not exactly sure yet, but I think the issue is that the resources list is loaded lazily after the initial request to /admin/. So if for some reason a request (e.g. /admin/accounts/user/1) was performed on a node that hasn't loaded the resources list yet, it fails.

If this is the case, the real fix is to somehow load the resources list as soon as the application starts. It's a bit tricky, but it needs to be fixed.

aesmail avatar Aug 08 '20 04:08 aesmail

I got permission to be able to contribute to bugfix this so, I might be able to tackle it later.

On application start I could just trigger the initial load, or quite literally just trigger

Kaffy.Utils.full_resources(nil)

EdBondArcher avatar Aug 13 '20 02:08 EdBondArcher

I had a working system and then tried to install authentication using mix phx.gen.auth Accounts User users as per the phx.gen.auth documentaiton. Now Kaffy falls over with this same error and Kaffy.Utils.full_resources(nil) returns ** (UndefinedFunctionError) function Kaffy.Utils.full_resources/1 is undefined (module Kaffy.Utils is not available)

Adding an account to the system database fixes this problem. So it appears when the authentication database is empty there is some strange issues. So I think you can ignore this comment completely.

semdinsp avatar May 25 '21 03:05 semdinsp