Skip to content

fix(rails): don't load Active Record or Active Job when enabling solid_queue_recurring - #3242

Open
pcbeingused333 wants to merge 2 commits into
getsentry:masterfrom
pcbeingused333:fix/solid-queue-recurring-lazy-load
Open

pcbeingused333 wants to merge 2 commits into
getsentry:masterfrom
pcbeingused333:fix/solid-queue-recurring-lazy-load

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #3237

With config.enabled_patches << :solid_queue_recurring and eager loading off, a to_prepare callback evaluated ::SolidQueue::RecurringTask < .... That autoloaded the model, and with it Active Record and Active Job, before the application had finished initializing, so Rails logged its early load hook warnings.

The prepend now runs from Rails.autoloaders.main.on_load("SolidQueue::RecurringTask"), as suggested in the issue. It fires when the model is first loaded and again after each code reload. If the model is already loaded when the patch is applied (for example Sentry.init after boot), it is patched right away.

A new isolated spec boots a fresh Rails app with eager loading off and on. With it off, it checks that neither framework is loaded before initialization and that the patch survives a reload. The eager loading off case fails without the fix.

No CHANGELOG.md entry, following AGENTS.md.

This change was prepared with AI assistance.

…d_queue_recurring

The patch checked SolidQueue::RecurringTask from a to_prepare callback, which autoloaded the model, and with it Active Record and Active Job, before the app finished initializing. Prepend from the autoloader's on_load callback instead.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@pcbeingused333
pcbeingused333 requested review from a team and solnic as code owners November 25, 2026 06:54

@solnic solnic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for addressing this. Please remove the regression spec though, it feels like an overkill to cover this specific case with a dedicated scenario. We could consider adding an e2e smoke test scenario later on to cover reloading/eager/lazy loading that would ensure our patches work as expected.

@pcbeingused333

Copy link
Copy Markdown
Author

Removed the isolated boot regression spec and its fixture as requested. The existing Solid Queue and recurring job specs passed with 90 examples on Rails 8.1.

This comment was drafted with Claude Code.

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 this pull request may close these issues.

:solid_queue_recurring patch loads Active Record and Active Job before initialization ("was loaded before application initialization")

2 participants