NoMethodError: undefined method `[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Ruby
- スター
- 730
- フォーク
- 155
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby-grape/grape-entity のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
ruby-grape/grape-entity#386 · コメント 7 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ruby-grape/grape-entity#382 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
ruby-grape/grape-entity#380 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
ruby-grape/grape-entity#373 · コメント 2 件 ·
-
Truncate Formatterオープン
難易度 1/5 1〜3時間 初心者へのやさしさ 45/100
ruby-grape/grape-entity#372 ·
ruby-grape/grape-entity の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ublue-os/homebrew-experimental-tap#774 ·
メンテナーはふだん 1 日以内に返信
-
accessibility
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
slovensko-digital/ops-portal#212 ·
メンテナーはふだん 1 日以内に返信
-
Local evaluation buckets percentage splits with the server key, so results differ from Flagsmithオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Add Prestashopオープンrequest
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
endoflife-date/endoflife.date#11303 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100