NameError on HttpResponse.new: OpenStruct is referenced in the sig block but never required
Avaliação
- Dificuldade
- 1/5
- Tempo estimado
- Menos de uma hora
- Facilidade para iniciantes
- 90/100
Direção de pesquisa
Comece em lib/shopify_api/clients/http_response.rb, onde OpenStruct aparece nos blocos sig por volta das linhas 15 e 31, e reproduza com o trecho require "shopify_api" fornecido. Adicione require "ostruct" nesse arquivo ou remova as referências a OpenStruct das assinaturas. Pronto significa que HttpResponse.new funciona sem um OpenStruct pré-carregado e os testes da gem ainda passam.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Ruby
- Estrelas
- 1.1k
- Forks
- 486
- Merge médio
- 1d 7h
- PRs com merge (30d)
- 4
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Shopify/shopify-api-ruby
-
devtools-gardener
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Shopify/shopify-api-ruby#1456 · 3 reações ·
-
2026-10 supportAbertadevtools-gardener
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 48/100
Shopify/shopify-api-ruby#1476 · 1 comentário ·
-
Allow configuring open/read timeouts for API requestsTalvez já em andamento @fluke assumiu há 51 dias. Abertadevtools-gardener
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
Shopify/shopify-api-ruby#1466 · 1 comentário ·
-
automated
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
Shopify/shopify-api-ruby#1465 ·
-
oj dependency breaks support for JRubyTalvez já em andamento @najibna assumiu há 64 dias. Abertadevtools-gardener
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 67/100
Shopify/shopify-api-ruby#1461 · 1 comentário ·
Todas as issues de Shopify/shopify-api-ruby
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
hanami/hanami-action#536 ·
-
[2026-11] Latest release (2026-11) still has expanded list entries that are no longer supportedAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Shopify/product-taxonomy#1054 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 13 dias
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
docker/model-runner#1118 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
TarteelAI/quranic-universal-library#1111 ·
Mantenedores costumam responder em até 1 dia