sferik / twitter-ruby

A Ruby interface to the Twitter API.
http://www.rubydoc.info/gems/twitter
MIT License
4.59k stars 1.31k forks source link

Undefined method `id' for nil:NilClass #1040

Closed 645383 closed 11 months ago

645383 commented 1 year ago

Problem

attrs = {id: 123, user: {id: 234...}...}
tweet = Twitter::Tweet.new(attrs)

tweet.user.id # raises error

NoMethodError: undefined method `id' for nil:NilClass

Expected It is expected to get NullObject in case if user can not be initialized:

attrs = {id: 123, user: {id: 234...}...}
tweet = Twitter::Tweet.new(attrs)

tweet.user.id # should not raise an error and should return NullObject

Question How is it possible to get such an error?

Context

  1. Code sample above is executed by multiple Sidekiq processes X threads
  2. attrs passed to initialization are regular tweet attrs with regular user attrs.

Thank you!