-
Notifications
You must be signed in to change notification settings - Fork 81
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
fix: Create request object per-page in getPaginatedResults(...) #536
fix: Create request object per-page in getPaginatedResults(...) #536
Conversation
@@ -161,6 +165,8 @@ func TestRequestHelpers_delete(t *testing.T) { | |||
} | |||
|
|||
func TestRequestHelpers_paginateAll(t *testing.T) { | |||
const totalResults = 4123 |
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 made this much larger and uneven to reproduce the failure case before applying the fix
|
||
// This request object cannot be reused for each page request | ||
// because it can lead to possible data corruption | ||
req := client.R(ctx).SetResult(resultType) |
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.
Another potential solution could've been to call req.SetResult(...)
at the beginning of this function but I wasn't 100% sure that wouldn't have unintended side-effects
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!
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.
Nice fix! Tests passed locally.
📝 Description
This PR fixes a bug that would cause corrupt/partially overridden data to be returned from endpoint methods that implement
getPaginatedResults[T any](...)
and have a large number of results.This issue occurred because Resty's request objects are not designed to be executed multiple times. Specifically, the internal
Request.Result
pointer (initialized by us usingSetResult(...)
) is not implicitly reset when executing a request multiple times, leading to new data being written on top of existing data.✔️ How to Test
Unit Testing
Manual Testing
Excluding manual testing steps for now since it requires a large number of resources (~ >200).