-
Notifications
You must be signed in to change notification settings - Fork 725
Description
Issue summary
Before opening this issue, I have:
- Upgraded to the latest version of the package
shopify_appversion: 23.0.1shopify_apiversion: 16.0.0- Ruby version: 3.2.1
- Rails version: 8.1.1
- Operating system: macOS Darwin 25.0.0
- Set
log_level: :debugin my configuration, if applicable - Found a reliable way to reproduce the problem that indicates it's a problem with the package
- Looked for similar issues in this repository (see Missing WebhookHandler #1977)
- Checked that this isn't an issue with a Shopify API
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
endWorkaround
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```