-
Notifications
You must be signed in to change notification settings - Fork 699
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
Refactor recreate webhooks logic #1686
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Hey @nelsonwittwer, thank you for the fix provided in this PR. I've upgraded Steps to reproduce:
[1] pry(main)> shop = Shop.last
=> #<Shop:0x000000010aaa8ee8 ... >
[2] pry(main)> session = ShopifyAPI::Auth::Session.new(shop: shop.shopify_domain, access_token: shop.shopify_token)
=> #<ShopifyAPI::Auth::Session:0x000000010aaeb040 ... >
[2] pry(main)> ShopifyAPI::Webhook.all(session: session).map { |webhook| webhook.original_state[:topic] }
=> ["app_subscriptions/update", "app/uninstalled", "bulk_operations/finish", "products/update", "products/create", "products/delete", "customers/create", "customers/update", "customers/delete"]
[3] pry(main)> ShopifyApp::WebhooksManager.recreate_webhooks!(session: session)
ShopifyAPI::Errors::WebhookRegistrationError: Failed to fetch webhook from Shopify: Argument 'topics' on Field 'webhookSubscriptions' has an invalid value (CUSTOMERS_DATA_REQUEST). Expected type '[WebhookSubscriptionTopic!]'.
from /Users/zuzannakusznir/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/shopify_api-12.4.0/lib/shopify_api/webhooks/registry.rb:154:in `get_webhook_id'
[1] pry(main)> shop = Shop.last
=> #<Shop:0x000000010aaa8ee8 ... >
[2] pry(main)> session = ShopifyAPI::Auth::Session.new(shop: shop.shopify_domain, access_token: shop.shopify_token)
=> #<ShopifyAPI::Auth::Session:0x000000010aaeb040 ... >
[3] pry(main)> ShopifyApp::WebhooksManager.recreate_webhooks!(session: session)
ShopifyAPI::Errors::WebhookRegistrationError: Failed to fetch webhook from Shopify: Argument 'topics' on Field 'webhookSubscriptions' has an invalid value (CUSTOMERS_DATA_REQUEST). Expected type '[WebhookSubscriptionTopic!]'.
from /Users/zuzannakusznir/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/shopify_api-13.0.0/lib/shopify_api/webhooks/registry.rb:154:in `get_webhook_id' Since the app is now running on gem version 21.5 I've expected not to receive this exception anymore - so I wanted to ask if there is anything wrong that you, or anyone else, can see in the steps to reproduce that I've listed above? And if the fix works for anyone else for existing Shop records? I would be really grateful for help with this one!
|
Experiencing the same while upgrading. Could we get some guidance on how to proceed? |
Same here. Any guidance on what to do here? |
Shopify docs state that mandatory webhooks should not be subscribed to via the API. I have submitted a pull request to remove them from generator templates and also fixed the recreation of webhooks in Also relates to Shopify/shopify-api-ruby#1123 and #1659 |
Actually, I think the issue is with shopify_app gem treating mandatory webhooks like any other webhook. I think they need to be treated separately as they are not API subscribable, must be (afaik) delivered over HTTP, and are global in scope, not per-install. It shouldn't be required to list them in config.webhooks but they should still be dispatched to a supplied Job class. |
It seems there is an issue with mandatory webhooks. I've created an issue with @zkusznir description and steps to reproduce that we will investigate. |
What this PR does
Fixes two bugs with webhooks within the app gem:
with_shopify_session
ShopifyApp::WebhhooksManager#recreate_webhooks!
was using API libraries methods to recreate webhooks instead of the methods it already had to do the same work. Since there were differing approaches with storing what topics were being used this was introducing bugs to consumers of both libraries.Should address Shopify/shopify-api-ruby#1123 and #1659
Reviewer's guide to testing
Use this branch with a shopify app created with the CLI. Create webhooks:
Checklist
Before submitting the PR, please consider if any of the following are needed:
CHANGELOG.md
if the changes would impact usersREADME.md
, if appropriate./docs
, if necessary