fix: Create request object per-page in getPaginatedResults(...)#536
Merged
lgarber-akamai merged 2 commits intolinode:mainfrom Jun 28, 2024
Merged
Conversation
lgarber-akamai
commented
Jun 27, 2024
| } | ||
|
|
||
| func TestRequestHelpers_paginateAll(t *testing.T) { | ||
| const totalResults = 4123 |
Contributor
Author
There was a problem hiding this comment.
I made this much larger and uneven to reproduce the failure case before applying the fix
lgarber-akamai
commented
Jun 27, 2024
|
|
||
| // This request object cannot be reused for each page request | ||
| // because it can lead to possible data corruption | ||
| req := client.R(ctx).SetResult(resultType) |
Contributor
Author
There was a problem hiding this comment.
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
yec-akamai
approved these changes
Jun 27, 2024
Contributor
yec-akamai
left a comment
There was a problem hiding this comment.
Nice fix! Tests passed locally.
10 tasks
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 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.Resultpointer (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).