Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] String.binary_to_existing_atom #140

Closed
EdBondArcher opened this issue Aug 7, 2020 · 8 comments
Closed

[BUG] String.binary_to_existing_atom #140

EdBondArcher opened this issue Aug 7, 2020 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@EdBondArcher
Copy link

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 EdBondArcher added the bug Something isn't working label Aug 7, 2020
@aesmail
Copy link
Owner

aesmail commented Aug 7, 2020

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?

@EdBondArcher
Copy link
Author

👋

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.

@aesmail
Copy link
Owner

aesmail commented Aug 7, 2020

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.

@EdBondArcher
Copy link
Author

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

@EdBondArcher
Copy link
Author

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

@aesmail
Copy link
Owner

aesmail commented Aug 8, 2020

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.

@EdBondArcher
Copy link
Author

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)

@semdinsp
Copy link

semdinsp commented May 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants