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 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Shopify/shopify-api-ruby 的其他 Issue
-
devtools-gardener
难度 2/5 1-3 小时 新手友好度 68/100
Shopify/shopify-api-ruby#1456 · 3 个 reaction ·
-
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 ·
-
难度 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 天内回复