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

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

Closed
DaveEshopGuide opened this issue Apr 16, 2024 · 4 comments · Fixed by #1313
Assignees

Comments

@DaveEshopGuide
Copy link
Contributor

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: Shopify/shopify_app#1830

@lizkenyon
Copy link
Contributor

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
Copy link
Contributor Author

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

@lizkenyon
Copy link
Contributor

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

DaveEshopGuide added a commit to eshopguide/shopify-api-ruby that referenced this issue Apr 17, 2024
…h, even if ShopifyAPI.Context.response_as_struct is true.

Had to add a Utility (ShopifyAPI::Utils::OstructHashUtils) to handle the conversion since a simple .to_h and even JSON.parse(response.body.to_json) did not work as expected (nested Keys and Array handling failed).
@DaveEshopGuide
Copy link
Contributor Author

@lizkenyon PR created.

@lizkenyon lizkenyon self-assigned this Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants