box-python-sdk
box-python-sdk copied to clipboard
Folder.get_items does not respect limit parameter
When I type folder.get_items(limit=1, sort='date', direction='DESC')
it still returns all the files in the folder.
{'Date': 'Tue, 23 Aug 2022 20:16:26 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'x-envoy-upstream-service-time': '198', 'box-request-id': '0a2e03ebc0aadeb94134f348da9bd6595', 'cache-control': 'no-cache, no-store', 'strict-transport-security': 'max-age=31536000', 'Via': '1.1 google', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"'}
{'entries': [{'etag': '1',
'file_version': {'id': '693104252949',
'sha1': '4c1688583a292cb89b91db9be7b3ace7ea7796d8',
'type': 'file_version'},
'id': '653772610149',
'name': "Joey's Email Handler Test File Template.csv",
'sequence_id': '1',
'sha1': '4c1688583a292cb89b91db9be7b3ace7ea7796d8',
'type': 'file'}],
'limit': 1,
'offset': 1,
'order': [{'by': 'type', 'direction': 'ASC'},
{'by': 'date', 'direction': 'DESC'}],
'total_count': 2}
Am I doing something wrong here?
Hi @joeree,
There is actually one file item with id: 653772610149
in this response that is on the entry
field which is an array.
You probably got confused because of the total_count
field which points to 2.
But as the documentation says about total_count
here
One greater than the shift of the last entry in the entire collection. The total number of entries in the collection can be less than total_count.
Hope it helped you, @arjankowski
Please see #366 - limit
refers to the page size when we request items from the Box API, not the maximum number of items we'll return from the SDK method call.
The naming is a little confusing - sorry about that.
Is it possible to request just one page then and not have all of them?
There is no direct way to do this in our SDK. Take a look at the link mentioned by Jeff here, where can you find a workaround for this issue:
If you really want to limit items, maybe using itertools will solve your issue.
Something like this: items = itertools.islice(get_items(..., limit=limit), limit)
This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.
This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box Python SDK and feel free to open another PR/issue at any time.