Skip to content

WebhooksManager passes class instead of instance to Registry.add_registration (incompatible with shopify_api v16) #2045

@sljmn

Description

@sljmn

Issue summary

Before opening this issue, I have:

  • Upgraded to the latest version of the package
    • shopify_app version: 23.0.1
    • shopify_api version: 16.0.0
    • Ruby version: 3.2.1
    • Rails version: 8.1.1
    • Operating system: macOS Darwin 25.0.0
  • Set log_level: :debug in 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

  1. Create a new Rails 8 app: rails new myapp --database=postgresql
  2. Add shopify_app: bundle add shopify_app
  3. Run generator: rails generate shopify_app
  4. Run server: rails s
  5. 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```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions