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

Rails autoloading fails when ::Collection is undefined #6736

Closed
marrus-sh opened this issue Mar 5, 2024 · 2 comments · Fixed by #6758
Closed

Rails autoloading fails when ::Collection is undefined #6736

marrus-sh opened this issue Mar 5, 2024 · 2 comments · Fixed by #6758

Comments

@marrus-sh
Copy link
Collaborator

marrus-sh commented Mar 5, 2024

The change made in 53b0060 doesn’t actually work in environments with autoloading when there is no ::Collection; the .safe_constantize creates a recursive loop which just tries to load the same file again.

We got around this by just doing Object.const_set(:Collection, Hyrax.config.collection_class) in an initializer, but this isn’t ideal.

@marrus-sh
Copy link
Collaborator Author

If you need :Collection to be nil in an initializer (for example, so that Valkyrie.config.resource_class_resolver can define it), the following worked for me :—

Object.const_set(:Collection, true)
require_dependency "#{Gem.loaded_specs["hyrax"].full_gem_path}/app/models/collection"
Object.send(:remove_const, :Collection)

@marrus-sh
Copy link
Collaborator Author

Digging a little more into this… this only happens when ::Collection is referenced in an initializer (outside of e·g a to_prepare). If Rails manages to complete initialization, then the implemented solution seems to work.

Not sure why this is exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant