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

fixes #6248 - API V2 return object for POST/PUT/DELETE should *not* include root node #1518

Closed
wants to merge 1 commit into from

Conversation

isratrade
Copy link
Member

No description provided.

@domcleal
Copy link
Contributor

Won't this change v1 too?

@isratrade
Copy link
Member Author

@daviddavis, ping. Can you check if this fix makes this more consistent. The object returned on POST/PUT/DELETE now has no node. I don't think it affects anything on json parameters received or GET request that use RABL templates.

@isratrade
Copy link
Member Author

@domcleal, yes, it will change v1. I guess it's a no go.

@isratrade
Copy link
Member Author

@daviddavis, this will probably not be merged per @domcleal's comment above.

@isratrade
Copy link
Member Author

@daviddavis, there are also several test failures locally caused by this change.

@daviddavis
Copy link
Contributor

So, to sum up, I guess our options are:

  1. Leave it as is for now (hopefully we can find a fix in the future)
  2. Change katello to return root nodes for POST/PUT/DELETE calls to be more consistent
  3. Find another solution that only affects v2.

I'm fine with #1 suppose. I think #2 is a bad idea. #3 seems best purely in theory but it's not feasible?

EDIT: Would there be a way to use the show rabl templates for DELETE/PUT/POST requests? I believe this is what we're doing in Katello. This sounds like the best in terms of consistency not only with Katello but also with show requests within foreman.

@waldenraines
Copy link

Is the third option really not feasible? I'm fine with option 1 or option 3. The second option would be largely destabilizing to katello.

@thomasmckay
Copy link
Contributor

we agreed a long time ago to the non-nested format
http://theforeman.org/manuals/1.5/index.html#5.1.3JSONResponseFormatforSingleObjects

@@ -9,6 +9,11 @@ class BaseController < Api::BaseController
end

before_filter :setup_has_many_params, :only => [:create, :update]
# override true value defined in config/initializers/wrap_parameters.rb for V2 responses for POST, PUT, DELETE
before_filter :except => [:index] do
resource_class.include_root_in_json = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waldenraines, @daviddavis, I reviewed katello code and see how you are rendering RABL templates for each each action with respond_for_#{action}

Foreman is essentially just doing render :json => @resource for the response for PUT/POST/DELETE

This fix changing resource_class.include_root_in_json = false in Api::V2::BaseController fixes the issue without affecting V1.

In doing so, I noticed the inflection bug with "HostClass" and "HostgroupClass"

If this before_filter is also on the index actions, then several tests fail (dashboard, statistics, autosign, etc). I didn't investigate these failures as they don't affect our consistency in documentation between katello and foreman. All tests pass with :except => [:index]

@isratrade
Copy link
Member Author

[test]

@daviddavis
Copy link
Contributor

@isratrade thanks for fixing this.

@isratrade
Copy link
Member Author

[test] interesting that SettingsControllerTest fails. This patch shouldn't touch it. My assumption is that once Setting.include_root_in_json = false is run by the API v2 controller, it persists for the model and affects everything else including API v1, so this solution won't work. Will need to re-think a new solution.

@daviddavis
Copy link
Contributor

@isratrade interesting. what about putting the before filter into api base controller and then set include_root_in_json to true or false based on whether it's v1 or v2 respectively.

@daviddavis
Copy link
Contributor

Also, since we're close to the end of the release and because this may cause instability, do we maybe want to wait on merging it?

@isratrade
Copy link
Member Author

@domcleal, @daviddavis, this should work for V1 and V2 as expected. All tests pass.

@isratrade isratrade changed the title fixes #4181 - API V2 return object for POST/PUT/DELETE should *not* include root node fixes #5080 - API V2 return object for POST/PUT/DELETE should *not* include root node Jun 18, 2014
@daviddavis
Copy link
Contributor

@isratrade can you update your commit to point to http://projects.theforeman.org/issues/6248? #5880 got accidentally deleted. Thanks.

@isratrade isratrade changed the title fixes #5080 - API V2 return object for POST/PUT/DELETE should *not* include root node fixes #6248 - API V2 return object for POST/PUT/DELETE should *not* include root node Jun 19, 2014
@@ -13,7 +13,7 @@ def test_update_valid
assert :success
response = ActiveSupport::JSON.decode(@response.body)
assert !response.empty?
assert_equal new_value, response['setting']['value']
assert_equal new_value, response['value']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates a break in the UI which uses AJAX to update the saved value when editing settings. Mine's showing a load of AJAX when I change a value now.

I guess the change to the default will affect all UI controllers - do we need to add a before_filter in the ApplicationController so it remains true for them?

@@ -13,6 +13,8 @@ class ApplicationController < ActionController::Base
helper 'layout'
helper_method :authorizer

# ensure include_root_in_json = true
before_filter { ActiveRecord::Base.include_root_in_json = true }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this and re-committed.

@@ -9,6 +9,9 @@ class BaseController < Api::BaseController
end

before_filter :setup_has_many_params, :only => [:create, :update]
# ensure include_root_in_json = false in case it was overridden by Api::V1 to true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use an around_filter I think, then we can restore it back to the previous value reliably?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domcleal, that makes sense. good idea. will do.

@@ -9,6 +9,9 @@ class BaseController < Api::BaseController
end

before_filter :setup_has_many_params, :only => [:create, :update]
# ensure include_root_in_json = false for V2 only
around_filter :disable_json_root
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated PR using around_filter

@domcleal
Copy link
Contributor

Merged as 301e9dc for Foreman 1.6.0, thanks @isratrade.

@domcleal domcleal closed this Jun 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants