Skip to content
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

[Next Major] prevent autopagination from mutating #2899

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

richardm-stripe
Copy link
Contributor

This PR causes .ListAutoPaging and .SearchAutoPaging not to mutate the user-provided options argument.

Before this change, there would be a subtle bug/confusing behavior if you ever re-used the same options across multiple list requests: e.g. suppose there are 4 customers ["a", "b", "c", "d"].

var options = new CustomerListOptions()
{
  Limit = 2
};
var service = new CustomerService();

// GET /v1/customers?limit=2 ["a", "b"]
// GET /v1/customers?starting_after=b&limit=2 ["c", "d"]
foreach (var cus of in service.ListAutoPaging(options)) {
  ...
}

// Would not start at the beginning because `options` was mutated.
// GET /v1/customers?starting_after=b&limit=2 ["c", "d"]
foreach (var cus of in service.ListAutoPaging(options)) {
  ...
}

There's a small chance that a user is dependent on this behavior, e.g. you can imagine somebody doing

foreach (var cus of in service.ListAutoPaging(options)) { ... }

var firstIdOfLastPage = options.StartingAfter;
var didAnyPagination = options.StartingAfter != null;

so out of conservatism I would wait to change this behavior until the next major version but I'm open to persuasion just to ship it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant