NameError on HttpResponse.new: OpenStruct is referenced in the sig block but never required
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 90/100
Hướng nghiên cứu
Bắt đầu trong lib/shopify_api/clients/http_response.rb, nơi OpenStruct xuất hiện trong các khối sig quanh dòng 15 và 31, và tái hiện bằng đoạn require "shopify_api" được cung cấp. Thêm require "ostruct" vào tệp đó hoặc xóa các tham chiếu OpenStruct khỏi các chữ ký. Hoàn tất nghĩa là HttpResponse.new hoạt động mà không cần OpenStruct được nạp trước và các bài kiểm tra của gem vẫn chạy qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Ruby
- Star
- 1.1k
- Fork
- 486
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Shopify/shopify-api-ruby
-
devtools-gardener
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Shopify/shopify-api-ruby#1456 · 3 reaction ·
-
2026-10 supportĐang mởdevtools-gardener
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
Shopify/shopify-api-ruby#1476 · 1 bình luận ·
-
Allow configuring open/read timeouts for API requestsCó thể đã có người làm @fluke đã nhận 51 ngày trước. Đang mởdevtools-gardener
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Shopify/shopify-api-ruby#1466 · 1 bình luận ·
-
automated
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Shopify/shopify-api-ruby#1465 ·
-
oj dependency breaks support for JRubyCó thể đã có người làm @najibna đã nhận 64 ngày trước. Đang mởdevtools-gardener
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
Shopify/shopify-api-ruby#1461 · 1 bình luận ·
Tất cả issue của Shopify/shopify-api-ruby
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
hanami/hanami-action#536 ·
-
[2026-11] Latest release (2026-11) still has expanded list entries that are no longer supportedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Shopify/product-taxonomy#1054 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 13 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
docker/model-runner#1118 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
TarteelAI/quranic-universal-library#1111 ·
Maintainer thường phản hồi trong vòng 1 ngày