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

Fix “::Collection” definition with autoloading #6758

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

marrus-sh
Copy link
Collaborator

In autoloaded environments which reference ::Collection in an initializer, safe_constantize will create a recursive autoloading loop. We can hook into ActiveSupport::Dependencies to check whether this is going to happen, and pre·emptively return false in that case (so that ::Collection is defined properly), without changing behaviour where ::Collection is getting safe_constantized from somewhere else.

Fixes

Fixes #6736

Copy link
Contributor

@no-reply no-reply left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuunnnnnnnn.

i'd love if this got cross institutional review, but it checks out to me.

In autoloaded environments which reference `::Collection` in an
initializer, `safe_constantize` will create a recursive autoloading loop.
We can hook into `ActiveSupport::Dependencies` to check whether this is
going to happen, and pre·emptively return `false` in that case (so that
`::Collection` is defined properly), without changing behaviour where
`::Collection` is getting `safe_constantize`d from somewhere else.
Copy link
Contributor

@dlpierce dlpierce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had encountered the circular dependency issue too, thanks for the improvement!

@dlpierce dlpierce merged commit 27499ad into main Mar 28, 2024
6 checks passed
@dlpierce dlpierce deleted the hyrax_fix_collection branch March 28, 2024 19:05
@dlpierce dlpierce added the notes-bugfix Release Notes: Fixed a bug label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes-bugfix Release Notes: Fixed a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails autoloading fails when ::Collection is undefined
3 participants