-
Notifications
You must be signed in to change notification settings - Fork 143
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
[WIP] Raise a BadRequestError if attribute isn't on resource #573
Conversation
obj = Rbac.filtered_object(resource) | ||
begin | ||
obj.try(:public_send, attribute) | ||
rescue => err |
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.
I believe this fix masks model issues in general and should not return the 400 but the 500 it does today. The request is indeed valid as reconfigure_dialog is a valid relationship for services (OPTIONS /api/services would show that) and thus GET /api/services/:id?attributes=reconfigure_dialog is a valid API request. The fix should be moved down to the model and in this particular case, the reconfigure_dialog would need to return a nil instead of stack tracing.
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.
So I suggested in the description changing 211 to Rbac.filtered_object(resource).try(:attribute)
so that it would, in fact, return nil.
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.
AFAIR the try will fail if the attribute/method exists and raises an exception, it will only return nil if it does not exist. The issue here is the begin/rescue masks the error and returns the 400/bad request when it is indeed a good request.
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.
I thought reconfigure_dialog was not defined on services...
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.
it is as a relationship. attributes= in the API allows one to not only query attributes, virtual attributes, but also relationships, which reconfigure_dialog is seen as such, do an OPTIONS /api/services to see the whole lot.
3b8b7ff
to
fdbb63f
Compare
fdbb63f
to
ebcf6d8
Compare
Checked commit d-m-u@ebcf6d8 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 app/controllers/api/base_controller/renderer.rb
|
@abellotti with the main pr it returns this: I was under the impression that this was the fix you wanted from our conversation last week but your comments here seem to indicate otherwise. Could you please clarify? |
Because this is a valid relationship, the expectation is that when the API fetches it, it would just get nil in this particular service, the model needs to be updated to just return nil for reconfigure_dialog if not applicable for that service. no changes needed in the API here. Note that this is important for bulk queries too, doing something like GET /api/services?attributes=reconfigure_dialog,id,name&expand=resources would fail with the bad_request when indeed it is a valid request. Expectation here is getting the expanded services, with id, name and reconfigure_dialog returned when valid (otherwise, nil and not returned in response). Hope this helps/clarifies it. |
@abellotti okay, then will you please go review ManageIQ/manageiq#18636 for me? |
I would expect
GET /api/services/:id?attributes=reconfigure_dialog
to return a bad request error rather than an internal_server_error fromundefined method `dialog_tabs' for nil:NilClass
. The issue is that we come into https://github.com/ManageIQ/manageiq/blob/master/app/models/service.rb#L338 and don't have a Reconfigure action, and then call try to find the tabs from https://github.com/ManageIQ/manageiq/blob/master/app/models/service.rb#L347.Fix for https://bugzilla.redhat.com/show_bug.cgi?id=1663972
Depends on:
ManageIQ/manageiq#18636