NoMethodError: undefined method `[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Ruby
- Star
- 730
- Fork
- 155
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby-grape/grape-entity
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
ruby-grape/grape-entity#386 · 7 bình luận · 1 reaction ·
-
Custom Entity options supportĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
ruby-grape/grape-entity#382 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
ruby-grape/grape-entity#380 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
ruby-grape/grape-entity#373 · 2 bình luận ·
-
Truncate FormatterĐang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 45/100
ruby-grape/grape-entity#372 ·
Tất cả issue của ruby-grape/grape-entity
Issue tương tự
-
chore
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
AllYourBot/hostedgpt#818 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[bug]: Sticky Streak DisappearedĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Použiť Redis pre ActionCableĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
slovensko-digital/autogram-portal#392 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
voxpupuli/puppet-quadlets#122 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
TheOdinProject/curriculum#31452 ·
Maintainer thường phản hồi trong vòng 1 ngày