Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Clearing polymorphic relationship by sending null data with PATCH is broken again

Đang mở
#1,081 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

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
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rails, ruby
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu trong lib/jsonapi/request_parser.rb tại parse_update_relationship_operation và so sánh hồi quy này với issue #656 cùng commit a232243f5e1e4a24cd9bb87406c5a229326e7ea2. Tái hiện yêu cầu PATCH relationship với một polymorphic association và null data; hoàn tất khi thao tác removal không còn gây ra undefined-method error và có regression test bao phủ trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The original issue #656 seems to have regressed, as the same error is now raised for a polymorphic association removal.

Started PATCH "/tags/830926030/relationships/taggable" for 127.0.0.1 at 2017-07-05 11:33:31 +0300
Processing by TagsController#update_relationship as HTML
  Parameters: {"data"=>nil, "relationship"=>"taggable", "tag_id"=>"830926030"}
Internal Server Error: undefined method `[]' for nil:NilClass /Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/request_parser.rb:594:in `parse_update_relationship_operation'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/request_parser.rb:133:in `parse_modify_relationship_action'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/request_parser.rb:98:in `setup_update_relationship_action'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/request_parser.rb:38:in `setup_action'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/request_parser.rb:27:in `initialize'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/acts_as_resource_controller.rb:66:in `new'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/acts_as_resource_controller.rb:66:in `process_request'
/Users/vesa/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/jsonapi-resources-0.9.0/lib/jsonapi/acts_as_resource_controller.rb:39:in `update_relationship'

The regression seems to stem from this commit a232243f5e1e4a24cd9bb87406c5a229326e7ea2 where operations were reworked to use an operation dispatcher and operation processors.

       if relationship.is_a?(JSONAPI::Relationship::ToOne)
         if relationship.polymorphic?
-          operation_args[1].merge!(
-            key_value: verified_params[:to_one].values[0] && verified_params[:to_one].values[0][:id],
-            key_type: verified_params[:to_one].values[0] && verified_params[:to_one].values[0][:type]
-          )
+          options[:key_value] = verified_params[:to_one].values[0][:id]
+          options[:key_type] = verified_params[:to_one].values[0][:type]

https://github.com/cerebris/jsonapi-resources/commit/a232243f5e1e4a24cd9bb87406c5a229326e7ea2#diff-a32d87f955d51d1e7270b1a974529f7eR585

I am not sure how to add tests to ensure this issue does not regress again. Any pointers on how you'd like to have such tests would be nice.

I discovered this issue as I'm adding special handling to jsonapi-authorization gem: https://github.com/venuu/jsonapi-authorization/pull/75

Ngôn ngữ chính
Ruby
Star
2.3k
Fork
546
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JSONAPI-Resources/jsonapi-resources

Tất cả issue của JSONAPI-Resources/jsonapi-resources

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.