Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.54k stars 2.76k forks source link

continuation_token populated even when end of data pages is reached if total pages is divisible by page_zize/max_rows param #32343

Open quadrillionio-js opened 11 months ago

quadrillionio-js commented 11 months ago

Describe the bug When paging through a Cosmos DB container using by_page(continuation_token), if the total number of pages is evenly divisible by passed max_item_count parameter (e.g., container has 9 items, max_item_count is set to 1 or 3), the continuation_token attribute is set for the last page of data (e.g., for a 9 item container with max_item_count set to 3, the second call passing a continuation_token which is the 3rd page of data).

To Reproduce using code similar to the code below:

    database = client.get_database_client(DATABASE_ID)
    container = database.get_container_client(CONTAINER_ID)

    query = "SELECT c.id, c.question_one, c.question_one_answer, c.question_two, \
        c.question_two_answer, c.question_three, c.question_three_answer FROM c"

    query_options = {
        "max_item_count": page_size,
        "enable_cross_partition_query": True
    }

    result_iterable = container.query_items(query=query, ** query_options)

    if (page_continuation != None):
        item_pages = result_iterable.by_page(page_continuation)
    else:
        item_pages = result_iterable.by_page()

    first_page = item_pages.next()
    continuation_token = item_pages.continuation_token

    results = list(first_page)

Expected behavior when the end of pages are reached, the continuation_token attribute should not populated.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context seems to work properly if the number of items in the container is not evenly divisible by the value of "max_item_count" e.g., container has 9 items, max_item_count = 4. On the third call to by_page(page_continuation), the continuation_token is not populated.

github-actions[bot] commented 11 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @pjohari-ms @simorenoh @AbhinavTrips @bambriz.