ruby-on-railsrubyrubygemsshopifyshopify-api

ShopifyAPI::InventoryLevel.delete deletes but also throws a NoMethodError


I'm using the ShopifyAPI Ruby gem. As part of the gem I can delete the InventoryLevel of a product at a specific location.

This works well:

  ShopifyAPI::InventoryLevel.delete(
    inventory_item_id: "correct_id",
    location_id: "and_another_correct_id"
  )

The issue is, is that after the level is deleted the API then throws this error:

NoMethodError (undefined method `empty?' for nil:NilClass)

This happens every time and I have no idea why.

This happening to anyone else? Any thoughts?


Solution

  • First, the error message tells you that something is calling nil.empty? when you trigger that method, so it's just a matter of finding out where that's happening.

    What version of the gem are you using? ShopifyAPI::InventoryLevel#delete just sends an API request, so an error like that is going to be somewhere in the gem's logic for how it handles the response to that request. Skimming the repo, the request method it's calling is probably ShopifyAPI::Clients::HttpClient#request. The #delete method is sending a DELETE request to their API, which should return a 204 No Content response. The HTTP Client file shows that they are calling .empty? and there is handling for a nil response body, but if you look at the file's version history you can see that this was added in a commit less than a year ago tagged v13.4.0. You're likely using a version of the gem older than that bugfix and just need to update it.