box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
418 stars 215 forks source link

Folder.get_items does not respect limit parameter #758

Closed joeysumi closed 1 year ago

joeysumi commented 2 years ago

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?

arjankowski commented 2 years ago

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

Jeff-Meadows commented 2 years ago

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.

joeysumi commented 2 years ago

Is it possible to request just one page then and not have all of them?

arjankowski commented 2 years ago

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)

stale[bot] commented 1 year ago

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.

stale[bot] commented 1 year ago

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.