NoMethodError: undefined method `[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
Start in lib/grape_entity/exposure/base.rb at Exposure::Base#serializable_value and reproduce the failure with the Post, Author, and PostEntity example in the issue. Compare the object, array, and hash serialization paths and the linked ActiveRecord serializable_hash behavior. Done means the example no longer raises NoMethodError and the corrected behavior is covered by a regression test.
Written by the indexing model from the issue text.
Description
When you have an entity which exposes an ActiveRecord belongs_to without a :using option, then serializable_hash is called with a Grape::Entity::Options object.
But serializable_hash clones the object and then tries to set :except on it. (It sets default :except to an empty array see here.) This causes the exception:
NoMethodError: undefined method '[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>
Not too big of a problem, it was just a forgotten :using, but it was very confusing.
Also depending on whether it's an object, array or hash, serializable_hash is called with or without options.
I'm talking about the code in Grape::Entity::Exposure::Base#serializable_value.
Should the options even be passed to serializable_hash at all? Or should []= be implemented?
This did work up until this commit btw.
Example to reproduce:
class Author < ActiveRecord::Base
end
class Post < ActiveRecord::Base
belongs_to :author
end
class PostEntity < Grape::Entity
expose :author # notice missing :using
end
PostEntity.represent(Post.first).as_json # => NoMethodError
- 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
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
betagouv/conseillers-entreprises#4720 ·
Maintainers usually reply within 3 days
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
zerocracy/judges-action#2692 · 1 comment ·
Maintainers usually reply within 6 days
-
agent:triaged bug bughunt pm:bundler priority:p1
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
SocketDev/socket-patch#896 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
eurosky-social/eu-haul#32 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
e0ipso/self-review#171 ·
Maintainers usually reply within 1 day