Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.06k stars 473 forks source link

TypeError in ShopifyApp::WebhooksManagerJob when ShopifyAPI::Context.response_as_struct is set to true #1311

Closed DaveEshopGuide closed 6 months ago

DaveEshopGuide commented 7 months ago

Issue summary

Hello,

I am encountering an issue with the ShopifyApp::WebhooksManagerJob when response_as_struct is set to true in the ShopifyAPI::Context.setup configuration.

Expected behavior

Webhooks registry should adapt to the response_as_struct setting and not throw an error.

Actual behavior

Webhooks registry throws an error on running the WebhooksManager

Steps to reproduce the problem

  1. Set response_as_struct to true in Shopify App Context
  2. Have one or more webhooks configured
  3. Install app triggering the execution of the WebhooksManager

Debug logs

class=ShopifyApp::WebhooksManagerJob jid=5f9296991f0ea1d916d3c55c ERROR: Error performing ShopifyApp::WebhooksManagerJob (Job ID: d541fd80-49ba-48aa-9cf7-adc575680edd) from Sidekiq(default) in 544.34ms: TypeError (T.cast: Expected type T::Hash[String, T.untyped], got type OpenStruct

11:14:01 jobworker.1 | Caller: C:/Users/David/.gem/ruby/3.1.0/gems/shopify_api-13.4.0/lib/shopify_api/webhooks/registry.rb:211):
11:14:01 jobworker.1 | C:/Users/David/.gem/ruby/3.1.0/gems/sorbet-runtime-0.5.11262/lib/types/private/casts.rb:18:in cast'
11:14:01 jobworker.1 | C:/Users/David/.gem/ruby/3.1.0/gems/sorbet-runtime-0.5.11262/lib/types/_types.rb:137:in cast'

This line parsed_check_result = registration.parse_check_result(T.cast(check_response.body, T::Hash[String, T.untyped])) should only expect T::Hash[String, T.untyped] if response_as_struct is false.

Also referenced here: https://github.com/Shopify/shopify_app/issues/1830

lizkenyon commented 7 months ago

Thanks for flagging this, and digging into the root cause!

If you want to put up a PR to resolve this the team would definitely review to get this out quickly. Otherwise we will look into fixing this in the near future.

DaveEshopGuide commented 7 months ago

@lizkenyon Have a Commit ready, but no permissions to push a branch it seems.

lizkenyon commented 7 months ago

@DaveEshopGuide You will need to create a fork of the repo, and then create a PR. Thanks so much!

DaveEshopGuide commented 7 months ago

@lizkenyon PR created.