Shopify / Shopify/shopify-api-ruby

obj.respond_to? :method_name isn't working correctly

Open
#1,273 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.1k
Forks
484
PR merge metrics
No merged PRs in 30d

Description

Issue summary

When using api_object.respond_to?(:method_name) the lib sometimes returns true and sometimes returns T::Private::Types::Void::VOID Sorbet private void type. It seems that true was returned if the method name had been previously used to dereference the object but on more inspection I am not so sure that's the case.

  • shopify_api version: 13.4
  • Ruby version:
  • Operating system:

Expected behavior

When calling respond_to? with a method name the object should return true if the object is able to respond to the method call or false if it is not, and if you call the method name on the object after it returns false it should raise a NoMethodError

Actual behavior

Sometimes the response is true, sometimes it's a private Sorbet type T::Private::Types::Void::VOID, and sometimes it switches from the private type to true after you dereference the object with the method in question.

Steps to reproduce the problem

  1. Instantiate an api object (I used a product)
  2. Invoke respond_to? on it ( api_object.respond_to? :some_bs_method )
  3. Bonus points - try invoking the method on the object after receiving the Sorbet type as a response and then calling respond_to? with the method name, it was returning true for me after doing so

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with shopify_api version 13.4 using the product API object and the respond_to? steps in the issue. Trace how respond_to? produces true, false, or T::Private::Types::Void::VOID; done means it consistently returns true or false and an unsupported call raises NoMethodError.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.