-
Notifications
You must be signed in to change notification settings - Fork 124
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
Bugfix: limit
and offset
params caused re-ordered resource list
#2702
Conversation
e29864f
to
35f7efa
Compare
## [1.19.2] - 2022-01-13 | ||
|
||
### Fixed | ||
- Previously, including `limit` or `offset` parameters to a resource list 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.
Lists should be surrounded by blank lines
@@ -114,7 +114,7 @@ def search account: nil, kind: nil, owner: nil, offset: nil, limit: nil, search: | |||
raise ArgumentError, "'offset' contains an invalid value. 'offset' must be an integer greater than or equal to 0." | |||
end | |||
|
|||
scope = scope.order(:resource_id).limit( |
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 is an excellent find, @john-odonnell!
However, I would suggest that the fix should be to make sure the order
is applied to all queries, rather than remove it for all queries (I didn't see another order instance, but I also may have missed it).
It's important that the order be consistent, and if no order is given, postgresql documents that there is no order guarantee.
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.
Good catch, thanks. I updated the PR to order the resources before limiting based on limit
& offset
.
# Sort results alphabetically by resource ID
scope = scope.order(:resource_id)
if offset || limit
...
35f7efa
to
5226879
Compare
5226879
to
357af55
Compare
Code Climate has analyzed commit 357af55 and detected 1 issue on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 90.0% (-1.5% change). View more on Code Climate. |
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.
LGTM! Thanks @john-odonnell!
Desired Outcome
From ONYX-14314:
Implemented Changes
By default, listed resources are ordered by time-of-creation, which means related resources are typically grouped. When
list
oroffset
parameters are provided, the listed resources are ordered alphabetically by resource ID, which means resources are grouped by type.I've removed the additional sorting when
list
oroffset
parameters are provided, so a limited or offset list will return resources in the expected order.Connected Issue/Story
CyberArk internal issue ID: ONYX-14314
Definition of Done
At least 1 todo must be completed in the sections below for the PR to be
merged.
Changelog
CHANGELOG update
Test coverage
changes, or
Documentation
README
s) were updated in this PRBehavior
Security