NameError on HttpResponse.new: OpenStruct is referenced in the sig block but never required
評価
調査の方向性
lib/shopify_api/clients/http_response.rb から始めます。ここでは OpenStruct が 15 行目と 31 行目付近の sig ブロックに現れます。提供された require "shopify_api" スニペットで再現してください。そのファイルに require "ostruct" を追加するか、シグネチャから OpenStruct への参照を削除します。完了とは、HttpResponse.new が事前に読み込まれた OpenStruct なしで動作し、gem のテストが引き続き通ることです。
索引モデルが issue の本文から書いたものです。
説明
Description
ShopifyAPI::Clients::HttpResponse references OpenStruct in its Sorbet sig blocks, but neither the file nor the gem root requires the stdlib:
lib/shopify_api/clients/http_response.rb:15: sig { returns(T.any(T::Hash[String, T.untyped], String, OpenStruct)) }
lib/shopify_api/clients/http_response.rb:31: body: T.any(T::Hash[String, T.untyped], String, OpenStruct),
require "shopify_api" succeeds, but the first HttpResponse.new raises NameError whenever OpenStruct has not already been loaded by something else. In the official Rails template (Shopify/shopify-app-template-ruby) nothing loads it, so the OAuth callback fails.
Steps to reproduce
Ruby 3.3.13, shopify_api 16.4.0:
require "shopify_api"
defined?(OpenStruct) # => nil
ShopifyAPI::Clients::HttpResponse.new(code: 200, headers: {}, body: OpenStruct.new(data: "x"))
Output:
require OK
OpenStruct depois: NAO
NameError: uninitialized constant OpenStruct
Real-world impact
Starting from Shopify/shopify-app-template-ruby at HEAD, running in RAILS_ENV=production, the app installs fine until the merchant approves the scopes. The redirect to /api/auth/callback then returns HTTP 500:
E NameError (uninitialized constant ShopifyAPI::Clients::HttpResponse::OpenStruct):
E shopify_api (16.4.0) lib/shopify_api/clients/http_response.rb:31:in `block in <class:HttpResponse>'
E sorbet-runtime (0.6.13681) lib/types/private/methods/_methods.rb:562:in `instance_exec'
The token exchange never completes, so Shop/User rows are never written and the app cannot be used. It happens on every install, in a clean template, in production mode.
Parameters: {"code"=>"...", "hmac"=>"...", "host"=>"...", "shop"=>"example.myshopify.com", "state"=>"...", "timestamp"=>"..."}
Completed 500 Internal Server Error in 96ms
Workaround
# config/initializers/zz_ostruct.rb
require "ostruct"
With that file present the callback completes normally and the session is stored.
Suggested fix
Add require "ostruct" to lib/shopify_api/clients/http_response.rb, or replace OpenStruct in the signatures with T.untyped / a concrete type. Relying on load order for a stdlib constant referenced in a sig is fragile, and the Sorbet runtime evaluates these signatures lazily at call time rather than at require time, which is why the gem loads cleanly and only breaks on first use.
Environment
shopify_api16.4.0 (~> 16.0)shopify_app23.0.3- Ruby 3.3.13
- Rails 7.1.6
RAILS_ENV=production, Ruby 3.3 official Docker image- Installed from
Shopify/shopify-app-template-rubyHEAD
- 主要言語
- Ruby
- スター
- 1.1k
- フォーク
- 486
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Shopify/shopify-api-ruby のほかの issue
-
devtools-gardener
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Shopify/shopify-api-ruby#1456 · リアクション 3 件 ·
-
2026-10 supportオープンdevtools-gardener
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
Shopify/shopify-api-ruby#1476 · コメント 1 件 ·
-
Allow configuring open/read timeouts for API requests対応中かも @fluke が 51 日前に担当しました。 オープンdevtools-gardener
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
Shopify/shopify-api-ruby#1466 · コメント 1 件 ·
-
automated
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
Shopify/shopify-api-ruby#1465 ·
-
oj dependency breaks support for JRuby対応中かも @najibna が 64 日前に担当しました。 オープンdevtools-gardener
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
Shopify/shopify-api-ruby#1461 · コメント 1 件 ·
Shopify/shopify-api-ruby の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
hanami/hanami-action#536 ·
-
[2026-11] Latest release (2026-11) still has expanded list entries that are no longer supportedオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Shopify/product-taxonomy#1054 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 13 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
docker/model-runner#1118 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
TarteelAI/quranic-universal-library#1111 ·
メンテナーはふだん 1 日以内に返信