janko / rodauth-model

Password attribute and associations for Rodauth account model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix already initialized constant Account::VerificationKey warning

bkuhlmann opened this issue · comments

Overview

Hello. 👋 I'm experiencing an issue where I'm seeing a bunch of warnings in my console (dev and test) when using Rodauth in my Rails app:

/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: already initialized constant Account::VerificationKey
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: previous definition of VerificationKey was here
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: already initialized constant Account::RememberKey
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: previous definition of RememberKey was here
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: already initialized constant Account::PasswordResetKey
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: previous definition of PasswordResetKey was here
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: already initialized constant Account::LoginChangeKey
/Users/bkuhlmann/.cache/frum/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rodauth-model-0.2.1/lib/rodauth/model/active_record.rb:69: warning: previous definition of LoginChangeKey was here

Steps to Recreate

I'm afraid I don't have a quick way to reproduce this for you in an isolated environment but can try to do that if it'd help. I mostly wanted to report this in case you weren't aware. As a workaround, I can use the excellent Warning gem to workaround these issues.

Environment

  • Ruby: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22.4.0]
  • Rails: 7.0.4
  • Rodauth: 2.29.0

Thanks for reporting. The only way I can see this happening is if your Account model is being loaded twice, which is likely to cause other issues/warnings anyway. I suggest you try to figure out why/if your model is being loaded multiple times.

Does it happen during code reloading, i.e. when you change files in your project? I know Zeitwerk is supposed to unload the Account constant before loading the file again, so this problem shouldn't appear. I couldn't reproduce this warning on the demo app.

Hey Janko, thanks. 🙇 I'm finding this hard to track down at the moment so believe this issue is more obscure than I realized. I think you are right that there is something I'm not seeing in the application which is causing this to happen. I'm going to close this issue since there is no reason to hold you up on this. If I am able to detect the root cause -- and it's actionable -- I can reopen this issue.