Shopify / Shopify/shopify_app

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

Open
#2,045 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.9k
Forks
739
Avg merge
21h 2m
Merged PRs (30d)
1

Description

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 #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```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/shopify_app/managers/webhooks_manager.rb at line 49 and inspect webhook_job_klass alongside ShopifyAPI::Webhooks::Registry.add_registration. Reproduce with the listed Rails generator and server commands using shopify_api 16.0.0; done means the generated app starts without the Sorbet TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.