Skip to content

Deprecation warning when using Zeitwerk and loading custom session class in initializer #164

@jerryjohnjacob

Description

@jerryjohnjacob

I have a use case which requires a custom ActiveRecord session class implementation, and I provide that configuration as specified here:

ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass

I think an ideal location to put this line is a Rails initializer. However, since Zeitwerk comes enabled with Rails 6 by default, new apps have started throwing a deprecation warning:

DEPRECATION WARNING: Initialization autoloaded the constant MySessionClass.

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 MySessionClass, for example,
the expected changes won't be reflected in that stale Class object.

These autoloaded constants have been unloaded.

It seems just writing this line in an initializer is going to raise an error in a future version of Rails. Please advise on the best method to resolve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions