Shopify / shopify_app

A Rails Engine for building Shopify Apps
MIT License
1.74k stars 683 forks source link

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

Closed DaveEshopGuide closed 2 months ago

DaveEshopGuide commented 2 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.

DaveEshopGuide commented 2 months ago

This should be fixed in the shopify_api repo, but for reference i also created this issue here since it happens with the shopify_app and shopify_api gems interacting

lizkenyon commented 2 months ago

I will close this issue for now, and we can track with 1311 Thanks again for flagging!