Skip to content

Commit 989315d

Browse files
lizkenyonclaude
andcommitted
Fix Rails 7.1 Zeitwerk eager loading in engine initializer
Rails 7.1 minimum version upgrade exposed timing issue where engine initializer tried to access job classes before Zeitwerk loaded them. Problem: - bin/rails zeitwerk:check failed with "uninitialized constant" errors - Production environments with config.eager_load = true would fail during boot - ActiveSupport.on_load(:active_job) hook runs when ActiveJob framework loads, but job classes in app/jobs/ may not be loaded yet during eager loading Solution: - Replace on_load hook with config.after_initialize Ensures all classes are loaded before configuration runs, working correctly in both development (autoload) and production (eager load) environments - Add ShopifyApp:: namespace to job class references Required for explicit constant resolution during eager loading - Add Active Storage config for test dummy app Rails 7.1 requires config/storage.yml when eager loading is enabled Result: bin/rails zeitwerk:check now passes. Engine properly configures job logging in all loading scenarios. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ab2cff7 commit 989315d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/shopify_app/engine.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class Engine < Rails::Engine
2222
]
2323
end
2424

25-
initializer "shopify_app.redact_job_params" do
26-
ActiveSupport.on_load(:active_job) do
27-
if ActiveJob::Base.respond_to?(:log_arguments?)
28-
WebhooksManagerJob.log_arguments = false
29-
ScriptTagsManagerJob.log_arguments = false
30-
elsif ActiveJob::Logging::LogSubscriber.private_method_defined?(:args_info)
31-
ActiveJob::Logging::LogSubscriber.prepend(RedactJobParams)
32-
end
25+
config.after_initialize do
26+
if ActiveJob::Base.respond_to?(:log_arguments?)
27+
ShopifyApp::WebhooksManagerJob.log_arguments = false
28+
ShopifyApp::ScriptTagsManagerJob.log_arguments = false
29+
elsif ActiveJob::Logging::LogSubscriber.private_method_defined?(:args_info)
30+
ActiveJob::Logging::LogSubscriber.prepend(RedactJobParams)
3331
end
3432
end
3533
end

test/dummy/config/storage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test:
2+
service: Disk
3+
root: <%= Rails.root.join("tmp/storage") %>
4+
5+
local:
6+
service: Disk
7+
root: <%= Rails.root.join("storage") %>

0 commit comments

Comments
 (0)