You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Ruby on Rails I'm running into "NoMemoryError: Too deeply nested." with OJ's serialization within this gem. The suggested solution worked if I edited the OJ 'mode' to 'compat' and added the 'use_as_json' flag as follows:
OJ_OPTIONS = {
mode: :compat,
# use ruby's built-in serialization. If nil, OJ seems to default to ~15 decimal places of precision
float_precision: 0,
use_as_json: true
}.freeze
The fact that no one else runs into this makes me wonder if maybe there is something about Rails specifically that is causing this though haven't tracked it down. If it's possible to modify these OJ options for everyone and tests still pass it could be suggested as a solution.
I'm happy to offer a PR if it would be accepted.
The text was updated successfully, but these errors were encountered:
I'm running into the same problem too. In my case, it occurs when an activity is returning Ruby objects. If I simply change the Ruby objects to call #as_json on themselves and return the hash, it seems to be working. I haven't tried changing the OJ_OPTIONS.
I'm experiencing this on plain Ruby project as well, doesn't seems like it's Rails related. Suggested workaround of modifying OJ_OPTIONS on gem source code mitigates it.
Update: Nevermind, I tried to reproduce this with the final workflow I ended up with, but can't reproduce it.
We've run into this a few times, too. It usually seems to be caused by trying to serialize a model that has loaded recursive associations (e.g. book <-> author). OJ ends up in an infinite loop, and blows up.
In general, the default oj config does not seem to play nicely with ActiveRecord models, and accidentally returning an ActiveRecord instance can result in storing hundreds of KB as a workflow or activity result in Temporal 😬
When using Ruby on Rails I'm running into "NoMemoryError: Too deeply nested." with OJ's serialization within this gem. The suggested solution worked if I edited the OJ 'mode' to 'compat' and added the 'use_as_json' flag as follows:
The fact that no one else runs into this makes me wonder if maybe there is something about Rails specifically that is causing this though haven't tracked it down. If it's possible to modify these OJ options for everyone and tests still pass it could be suggested as a solution.
I'm happy to offer a PR if it would be accepted.
The text was updated successfully, but these errors were encountered: