Grape::Entity::Delegator::HashObject fails when extracting string keys
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
Research direction
Start in Grape::Entity::Delegator::HashObject, where attributes are extracted from the presented hash. Reproduce the issue with string-keyed values, then verify that string keys render correctly without breaking symbol-keyed hashes.
Written by the indexing model from the issue text.
Description
Hi,
I was trying to present a hash of values with a grape entity. The keys in the hash were strings and I got null values all over the place as a response.
It boils down to Grape::Entity::Delegator::HashObject, when it tries to render the attribute it only tries to extract the attribute with a symbol as a key and not a string.

I think a simple
object[attribute] || object[attribute.to_s]
would fix the issue, although I'm not sure whether you need to make the destinction between symbols and strings there for other reasons. For now I simple convert all my keys to symbols before handing them to grape entity. But in any case would be more convenient the other way around.
Cheers
Tom
- Dominant language
- Ruby
- Stars
- 730
- Forks
- 155
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from ruby-grape/grape-entity
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ruby-grape/grape-entity#386 · 7 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#382 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#380 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
ruby-grape/grape-entity#373 · 2 comments ·
-
Truncate FormatterOpen
Difficulty 1/5 1-3 hours Newbie friendliness 45/100
ruby-grape/grape-entity#372 ·
All issues in ruby-grape/grape-entity
Similar issues
-
bug priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
mitakarb/beerkeeper#1259 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
agent:triaged bug bughunt pm:bundler priority:p1
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
SocketDev/socket-patch#1125 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ecosyste-ms/funds#711 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 85/100
cloudflare/mcp#271 ·
Maintainers usually reply within 1 day