Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to json-encode a Twitter::NullObject with ActiveSupport results in SystemStackError #673

Merged
merged 1 commit into from
Mar 27, 2015

Conversation

lukevmorris
Copy link

Right after we upgraded to Rails 4.1, we started noticing periodic SystemStackErrors being raised by our application when performing and rendering results from Twitter::REST::Client#search. This appears to be caused by an interaction between Twitter::NullObject and ActiveSupport::JSON::Encoding::JSONGemEncoder#jsonify, where:

null_attr = Twitter::NullObject.new
ActiveSupport::JSON.encode(null_attr)

results in an infinite loop:

ActiveSupport::JSON::Encoding::JSONGemEncoder:79 - jsonify
Twitter::NullObject::GeneratedMethods:90 - method_missing
Twitter::NullObject::GeneratedMethods:27 - method_missing
ActiveSupport::JSON::Encoding::JSONGemEncoder:79 - jsonify
Twitter::NullObject::GeneratedMethods:90 - method_missing
Twitter::NullObject::GeneratedMethods:27 - method_missing
...

and eventually:

SystemStackError: stack level too deep

This pull request gives Twitter::NullObject the knowledge that its json representation is 'null', and thereby allows #jsonify to exit its infinite recursion. This seems to me to be a reasonable addition to NullObject's responsibilities, though I can definitely see an argument that it shouldn't be concerned at all with json encoding. Let me know what you think and whether there are any additional changes you'd like me to make.

@lukevmorris lukevmorris force-pushed the fix/null_object_as_json branch from b6ca524 to db8e56d Compare March 27, 2015 18:54
@lukevmorris lukevmorris force-pushed the fix/null_object_as_json branch from db8e56d to ef71f50 Compare March 27, 2015 18:56
@sferik
Copy link
Owner

sferik commented Mar 27, 2015

I’m okay with this. Thanks for the patch. I’ll merge it into the master branch, which is tracking the next major release (a.k.a. v6). If necessary, I can also backport it into the 5-stable branch and push a bugfix release (5.14.1). Let me know what your needs are.

sferik added a commit that referenced this pull request Mar 27, 2015
Attempting to json-encode a Twitter::NullObject with ActiveSupport results in SystemStackError
@sferik sferik merged commit 0c20995 into sferik:master Mar 27, 2015
@lukevmorris
Copy link
Author

Thanks @sferik. A backport would be very convenient if v6 is still a ways off.

@lukevmorris lukevmorris deleted the fix/null_object_as_json branch March 27, 2015 21:01
@lukevmorris lukevmorris restored the fix/null_object_as_json branch March 27, 2015 21:02
@sferik
Copy link
Owner

sferik commented Mar 27, 2015

@lukevmorris There are still lots of open issues for v6, so I’ll backport your changes now. I’m not going to ship a new gem right away but ping me again when you need that.

@sferik
Copy link
Owner

sferik commented Mar 28, 2015

@lukevmorris Okay, I’ve cherry-picked your change into the 5-stable branch: 0f8bd7e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants