Skip to content

User.shop throws a NilClass error without code change #146

@jetblackstar

Description

@jetblackstar

So on a system that has remained unchanged for months, this exception started coming up today.

I've not fully ruled out the user doing something but I don't think they could have broken this.

Getting the following exception on Console as an example. (validusername is obviously not a real username/id)

Etsy.user('validusername').shop

NoMethodError: undefined method `associated_shops' for nil:NilClass
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/etsy-0.3.3/lib/etsy/user.rb:80:in `shops'
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/etsy-0.3.3/lib/etsy/user.rb:46:in `shop'
        from (irb):12
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
        from /home/ubuntu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

Etsy.user('validusername') does return a valid Etsy::User response.

But looking into the code of the Etsy Gem,
etsy/user.rb;

          options = {:fields => 'user_id', :includes => 'Shops'}
          options = options.merge(:access_token => token, :access_secret => secret) if (token && secret)
          tmp = User.find(username, options)
          @shops = tmp.associated_shops.map { |shop| Shop.new(shop) }

Its tmp.associated_shops that is throwing the NilClass.
My guess is Shops is recently no longer is being allowed to include in the Etsy API? Or rather its just not returning a result to tmp in this query?

I've personally written around this issue by changing any calls of Etsy.user('validusername').shop to instead call Etsy::Shop.find('validshopid') which is probably a better way to directly access shop. But I wanted to flag this up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions