EasyPost / easypost-python

EasyPost Shipping API Client Library for Python
https://easypost.com/docs/api
MIT License
111 stars 57 forks source link

[fix] Fix, re-design implementation of pagination functions #307

Closed nwithan8 closed 1 year ago

nwithan8 commented 1 year ago

Description

As we've recently discovered, a bug in the implementation of the "get_next_page" functions in this library meant any specific filters used while getting pages for a given resource were not being preserved and carried forward (e.g. the type of report, a specific tracking code for trackers, "purchased" filter for shipments).

This PR redesigned the underlying implementation of the "get_next_page" functions to be more explicit and account for minor inconsistencies endpoint-to-endpoint by relying on a hidden "_filters" key that will carry necessary metadata about parameters and filters used for each "all" and "get_next_page" call for easy reference behind the scenes when retrieving the next page of a paginated collection. From an end-user perspective, this means they will not need to always pass in, e.g., the "purchased" filter for each page request of shipments, or the type of report for each page request of reports. Whatever filters were used to retrieve the first page of a paginated collection will be reused automatically behind-the-scenes when retrieving each subsequent page. ("page_size" is still on a per-page basis, and filters can be overridden with optional parameters if necessary). This more closely follows the design of pagination as implemented in the Java and .NET library, which were the original models for these functions.

This PR does not change the majority of the end-user experience or public function signatures. As demonstrated by the minor changes to the unit tests and the lack of need to re-record any cassettes, this implementation change does not alter the shape or workflow as it previously was.

The only "breaking changes" include:

Testing

Pull Request Type

Please select the option(s) that are relevant to this PR.