Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhooks jobs argument error #1351

Closed
1 task done
karimmtarek opened this issue Jan 12, 2022 · 4 comments
Closed
1 task done

Webhooks jobs argument error #1351

karimmtarek opened this issue Jan 12, 2022 · 4 comments
Labels

Comments

@karimmtarek
Copy link

karimmtarek commented Jan 12, 2022

Description

Recently I started getting this error, when webhooks jobs are called:

ArgumentError: wrong number of arguments (given 1, expected 0; required keywords: shop_domain, webhook)

Steps to Reproduce

  1. Generate a webhook rails g shopify_app:add_webhook -t carts/update -a https://example.com/webhooks/carts_update
  2. Wait for a webhook to come in
  3. Webhook argument error 🎉

Expected behavior:

I expect the webhook job generated by the generator to work.

Actual behavior:

Webhook job is erroring:

ArgumentError: wrong number of arguments (given 1, expected 0; required keywords: shop_domain, webhook)

Reproduces how often:

The error happens whenever a webhook job is called

Browsers

N/A

Gem versions

18.0.3

Additional Information

It seems that the webhook job arguments shop_domain, webhook, are now combined in a hash which is them being passed to the webhook job from the webhooks controller

# app-name/app/controllers/shopify_app/webhooks_controller.rb
module ShopifyApp
  class MissingWebhookJobError < StandardError; end

  class WebhooksController < ActionController::Base
    include ShopifyApp::WebhookVerification

    def receive
      params.permit!
      job_args = { shop_domain: shop_domain, webhook: webhook_params.to_h } # 👈
      webhook_job_klass.perform_later(job_args) # 👈
      head(:ok)
    end
    ...
end

Am I missing something? Or should the generated job change to this:

class CartsUpdateJob < ActiveJob::Base
  def perform(job_args)
    shop = Shop.find_by(job_args[:shop_domain])
    ...
  end
end

Or maybe the controller change to this

webhook_job_klass.perform_later(shop_domain: shop_domain, webhook: webhook_params.to_h)

Security

  • I have redacted any private information from my logs or code snippets.
@yourivdlans
Copy link

Are you on Ruby 3.x by any chance? There is an outstanding PR that fixes this issue: #1342

@karimmtarek
Copy link
Author

@yourivdlans yep I'm on Ruby 3.0, thanks for bringing my attention to the PR, hopefully it gets merged soon 🙏

@kirillplatonov
Copy link
Contributor

And the fix is merged! Thanks, @gonzaloriestra, and looking forward to the upcoming release 🙂

@gonzaloriestra
Copy link
Contributor

Version 18.1.0 released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants