stripe-python
stripe-python copied to clipboard
`auto_paging_iter` in conjunction with `ending_before` param reverses the order of `list` resource
Python Version: 3.7.2 Stripe Lib Version: 2.41.0
Calling auto_paging_iter()
reverses the order of the list resource:
In [1]: import stripe
In [2]: params = {
...: 'ending_before': 'evt_xxxx',
...: 'api_key': 'xxxx'
...: }
In [3]: events = stripe.Event.list(**params)
In [4]: for e in events:
...: print(e['id'])
evt_1GTBxxx
evt_1GTAxxx
evt_1GTAxxx
In [5]: for e in events.auto_paging_iter():
...: print(e['id'])
evt_1GTAzxxx
evt_1GTAzxxx
evt_1GTBxxx
I think this is a direct result of the fix for this issue. Maybe this is actually the intended behaviour, but I found the inconsistency confusing, so perhaps the docs could be updated if nothing else :)
@J-Priebe Thanks for the report! This is (as far as I know) expected behaviour so if you pass only ending_before
we start paginating at the end and will go back to the most recent objects. That's what our docs say here.
Does that make sense? If so which part of our docs is unclear?
Hey @remi-stripe , auto_paging_iter
actually behaves exactly as I would expect - it iterates backwards through events from oldest to newest in an unbroken order. My confusion comes from the fact that without auto_paging_iter
, event.List
still pages in the same direction (each page is newer events than the page before it), however within a page, the events are in the opposite order (newest to oldest).
I can sort of see the rationale for both; the former is reversing the entire sequence; the latter is just paging backwards without reversing the sequence within a page. But the documentation for auto-pagination suggests it is purely a convenience method for managing pagination, I don't think it mentions anywhere that it reverses the entire sequence. Thanks for reading!
Thanks for the report @J-Priebe. This is expected behavior, but I agree we should do a better job of documenting it. Going to leave this open for now and we'll try and clarify the behavior in a future version.
Closing, as we now clarified the relevant aspect of pagination/auto-pagination on the api reference