samvera / questioning_authority

Question your authorities
Other
54 stars 30 forks source link

address use of autoload in initializers which is deprecated #351

Closed elrayle closed 1 year ago

elrayle commented 2 years ago

Discussion

PR #349 added a check in initializers to avoid a deprecation warning related to the use of autoloaded constants in initializers. The use of autoloaded contants in initializers can have unpredictable behavior. It is deprecated and will be removed in "future versions of Rails".

The use in QA is to load yml file based authorities and configs for linked data authorities in an initializer at application load time. A side effect of the load is that @config is defined for 'local' authorities which holds the location of authority files in the filesystem.

The loading of these files by QA could be delayed until after full application load, but, at least at this time, Hyrax's initializer registers additional database local authorities which hits the same code. It also wants access to @config. This causes Hyrax apps to fail to load. To address this failure, PR #350 reverts the original PR.

This issue still needs to be addressed for future versions of Rails to work.

jrochkind commented 2 years ago

I think if you stop using Rails autoloading in the Gem, that should also avoid the deprecation notices. (I think. I could be wrong).

With no other change to code needed.

Except now I'm confused about that, because the autoloading we're doing here seems to be with the autoload method, which should be part of ruby, not part of rails/zeitwerk? So is that's what's triggering the deprecation warnings?

But... the deprecation warnings about using autoloaded constants. Why do we need to use autoloaded constants at all, can we just... stop?

Autoloading is used in Rails apps so you can see changes to code without having to stop and start the app. Is this needed for engine source code?

jrochkind commented 2 years ago

The deprecation notice is getting really annoying to me. Not sure if it's gotten worse or this is what it's always been. This is what I get in my logs:

DEPRECATION WARNING: Initialization autoloaded the constants Qa::LinkedData and Qa::LinkedData::AuthorityService.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Qa::LinkedData, for example,
the expected changes won't be reflected in that stale Module object.

These autoloaded constants have been unloaded.

In order to autoload safely at boot time, please wrap your code in a reloader
callback this way:

    Rails.application.reloader.to_prepare do
      # Autoload classes and modules needed at boot time here.
    end

That block runs when the application boots, and every time there is a reload.
For historical reasons, it may run twice, so it has to be idempotent.

Check the "Autoloading and Reloading Constants" guide to learn more about how
Rails autoloads and reloads.

Pretty annoying and distracting. :( This is making me consider forking and/or ceasing to use the gem, which seems to be teh only way to get this out of my logs. :(