"singleton can't be dumped" exception when trying to cache a BatchLoader field
bill-kolokithas opened this issue · 4 comments
Hello. When using BatchLoader gem to... batch load a field, the following error is returned when trying to cache it:
singleton can't be dumped
/home/billk/.gem/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/cache.rb:665:in `dump'
/home/billk/.gem/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/cache.rb:665:in `dup_value!'
/home/billk/.gem/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/cache/memory_store.rb:130:in `write_entry'
/home/billk/.gem/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/cache.rb:400:in `block in write'
...
I haven't tested with https://github.com/Shopify/graphql-batch. Maybe there is a problem with lazy fields in general?
I have the same issue when using Rails.cache
without this gem, so the problem is somewhere outside of graphql-cache
.
In my case, the reason was the fact that only serializable objects could be cached. e.g. I did try to cache FactoryBot build_stubbed
thing. @freestyl3r please check is it your case
Yeah, it's a limitation of Marshal used internally by rails cache.
Some objects cannot be dumped: if the objects to be dumped include bindings, procedure or method objects, instances of class IO, or singleton objects, a TypeError will be raised.
If we provide marshal_dump
& marshal_load
methods, maybe we can make this work.
Since this is a problem with Rails.cache
and not graphql-cache, I'm going to close this issue.