-
Notifications
You must be signed in to change notification settings - Fork 984
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
Conversation
Won't this change v1 too? |
@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. |
@domcleal, yes, it will change v1. I guess it's a no go. |
@daviddavis, this will probably not be merged per @domcleal's comment above. |
@daviddavis, there are also several test failures locally caused by this change. |
So, to sum up, I guess our options are:
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. |
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. |
we agreed a long time ago to the non-nested format |
@@ -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 |
There was a problem hiding this comment.
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]
[test] |
@isratrade thanks for fixing this. |
[test] interesting that |
@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. |
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? |
@domcleal, @daviddavis, this should work for V1 and V2 as expected. All tests pass. |
@isratrade can you update your commit to point to http://projects.theforeman.org/issues/6248? #5880 got accidentally deleted. Thanks. |
@@ -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'] |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
…ld *not* include root node
Merged as 301e9dc for Foreman 1.6.0, thanks @isratrade. |
No description provided.