Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
valscion opened this issue Jul 5, 2017 · 2 comments

Comments

@valscion
Copy link
Contributor

valscion commented Jul 5, 2017

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 a232243 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]

a232243#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: venuu/jsonapi-authorization#75

@valscion
Copy link
Contributor Author

valscion commented Jul 5, 2017

A possible fix is in #1083 and just the failing test case demonstrating this issue is in #1082.

@valscion
Copy link
Contributor Author

valscion commented Mar 29, 2019

I verified this is still the case in jsonapi-resources v0.9.6.

The test case and possible fix in #1082 and #1083 are now outdated, though. I closed them both as this issue hasn't got any attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant