ruby-grape / ruby-grape/grape-entity
serializing Grape::Entity::Exposure::NestingExposure::OutputBuilder fails in 0.7.0
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
When attempting to serialize a Grape::Entity::Exposure::NestingExposure::OutputBuilder in 0.7.0 using Marshal.dump (for caching), we encounter an error like TypeError: can't dump IO.
Rails.cache.fetch(key) do
present(entity_items).as_json # this used to just give a Hash which could be marshaled properly
end
This error seems to stem from the options hash in the entity. When it contains the request environment (in the :env key), there are objects that cannot be marshaled.
In my testing (in development mode) the following keys contain unmarshalable items.
opts[:env].reject {|k,v| Marshal.dump(v) rescue false }.keys
["rack.errors",
"puma.socket",
"rack.hijack",
"puma.config",
"action_dispatch.logger",
"action_dispatch.backtrace_cleaner",
"action_dispatch.routes",
"action_dispatch.remote_ip",
"rack.session",
"rack.session.options",
"warden",
"grape.routing_args",
"api.endpoint"]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with Marshal.dump around the Rails.cache.fetch example, then inspect how the entity options hash carries opts[:env]. Use the listed unmarshalable environment keys to narrow the cause; done means the entity can be serialized for caching without the TypeError while retaining the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100