Issue summary
Before opening this issue, I have:
Fresh installation of shopify_app v23.0.1 crashes immediately on rails s or when running generators due to Sorbet type mismatch in WebhooksManager.add_registrations.
Expected behavior
Running rails generate shopify_app followed by rails s should start the server without errors.
Actual behavior
The app crashes with a Sorbet TypeError because WebhooksManager passes the webhook job class to ShopifyAPI::Webhooks::Registry.add_registration, but shopify_api v16 expects an instance of ShopifyAPI::Webhooks::WebhookHandler.
Steps to reproduce the problem
- Create a new Rails 8 app:
rails new myapp --database=postgresql
- Add shopify_app:
bundle add shopify_app
- Run generator:
rails generate shopify_app
- Run server:
rails s
- App crashes with TypeError
Debug logs
Parameter 'handler': Expected type T.nilable(ShopifyAPI::Webhooks::WebhookHandler), got type Class with value AppUninstalledJob (TypeError) Caller: /lib/types/private/methods/call_validation.rb:227 Definition: shopify_api-16.0.0/lib/shopify_api/webhooks/registry.rb:25 (ShopifyAPI::Webhooks::Registry.add_registration)
raise TypeError.new(opts[:pretty_message])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Root cause
In lib/shopify_app/managers/webhooks_manager.rb line 49:
handler: delivery_method == :http ? webhook_job_klass(webhook_path) : nil,
The webhook_job_klass method uses safe_constantize which returns the class, not an instance.
Suggested fix
handler: delivery_method == :http ? webhook_job_klass(webhook_path).new : nil,
Workaround
Create config/initializers/shopify_app_webhook_fix.rb:
```module ShopifyApp
class WebhooksManager
class << self
private
def webhook_job_klass(path)
klass = webhook_job_klass_name(path).safe_constantize || raise(::ShopifyApp::MissingWebhookJobError)
klass.new
end
end
end
end
Workaround
Create config/initializers/shopify_app_webhook_fix.rb:
class WebhooksManager
class << self
private
def webhook_job_klass(path)
klass = webhook_job_klass_name(path).safe_constantize || raise(::ShopifyApp::MissingWebhookJobError)
klass.new
end
end
end
end```
Issue summary
Before opening this issue, I have:
shopify_appversion: 23.0.1shopify_apiversion: 16.0.0log_level: :debugin my configuration, if applicableFresh installation of
shopify_appv23.0.1 crashes immediately onrails sor when running generators due to Sorbet type mismatch inWebhooksManager.add_registrations.Expected behavior
Running
rails generate shopify_appfollowed byrails sshould start the server without errors.Actual behavior
The app crashes with a Sorbet
TypeErrorbecauseWebhooksManagerpasses the webhook job class toShopifyAPI::Webhooks::Registry.add_registration, butshopify_apiv16 expects an instance ofShopifyAPI::Webhooks::WebhookHandler.Steps to reproduce the problem
rails new myapp --database=postgresqlbundle add shopify_apprails generate shopify_apprails sDebug logs
Parameter 'handler': Expected type T.nilable(ShopifyAPI::Webhooks::WebhookHandler), got type Class with value AppUninstalledJob (TypeError) Caller: /lib/types/private/methods/call_validation.rb:227 Definition: shopify_api-16.0.0/lib/shopify_api/webhooks/registry.rb:25 (ShopifyAPI::Webhooks::Registry.add_registration)
raise TypeError.new(opts[:pretty_message])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Root cause
In
lib/shopify_app/managers/webhooks_manager.rbline 49:Workaround
Create config/initializers/shopify_app_webhook_fix.rb: