Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchNext() does not return the first result #23771

Open
2 of 6 tasks
paulsmithkc opened this issue Nov 9, 2022 · 6 comments
Open
2 of 6 tasks

fetchNext() does not return the first result #23771

paulsmithkc opened this issue Nov 9, 2022 · 6 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team.
Milestone

Comments

@paulsmithkc
Copy link

paulsmithkc commented Nov 9, 2022

  • Package Name: @azure/cosmos
  • Package Version: 3.17.1
  • Operating system: MacOS and Azure App Services
  • nodejs
    • version: 14 and 16
  • browser
    • name/version:
  • typescript
    • version: 4.8.4
  • Is the bug related to documentation in

Describe the bug
After investigation we found that there is as any issue with the fetchNext() method that we are using, when we only expect one database result.

Sometimes the first call to fetchNext() will return an empty array of resources with hasMoreResults = true. In order to get the first record in this situation you have to call fetchNext() multiple times until you get a result, or hasMoreResults becomes comes false.

On the other hand fetchAll() will call fetchNext() multiple times until all the results are retrieved. (There are no more results.)

So we are switching all of the findOne() and similar methods over to use fetchAll() to avoid this problem.

To Reproduce
Steps to reproduce the behavior:

  1. Insert a bunch of records into a container, with different partition keys.
  2. Try to query for a single document with a unique identifier that is not the id/pk of the container. (This means that the queries will be cross partition queries.)
  3. Try Step 2 for all documents in the container, until one fails to be returned by the first call to fetchNext()
  4. This behavior will repeatable for the document identified in Step 3

Expected behavior
The first call to fetchNext() always returns the first query result.

Actual behavior
The first call to fetchNext() does not always return the first result.

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

Additional context
Add any other context about the problem here.

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Nov 9, 2022
@azure-sdk azure-sdk added Client This issue points to a problem in the data-plane of the library. Cosmos needs-team-triage This issue needs the team to triage. labels Nov 9, 2022
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Nov 9, 2022
@xirzec xirzec removed the needs-team-triage This issue needs the team to triage. label Nov 9, 2022
@sajeetharan
Copy link
Member

hi @paulsmithkc This is the expected behaviour, hasMoreResults is always true by default, it gets set to false after fetchNext if there is no more continuation!

@paulsmithkc
Copy link
Author

@sajeetharan You misunderstood the issue.

Previously the first time fetchNext returned, it would include a result. Now you have to call fetchNext() multiple times to get the first result.

@v1k1 v1k1 reopened this Jan 17, 2023
@v1k1
Copy link
Member

v1k1 commented Jan 17, 2023

Reopening to investigate further.

@abkolant-MSFT
Copy link

@paulsmithkc

Previously the first time fetchNext returned, it would include a result. Now you have to call fetchNext() multiple times to get the first result.

By "Previously" you mean at an earlier time when the database had different number of entities? This is possible because the paritions might have been different. We have a gist that describes this issue here.

Could you clarify what you meant by "Previously"?

@paulsmithkc
Copy link
Author

I think that gist accurately describes the problem.

  • Is there a reason it is labelled "secret" rather than being searchable?

  • Should that gist be included in the API docs, to help explain usage/expectations for fetchNext() ?

@xirzec xirzec added bug This issue requires a change to an existing behavior in the product in order to be resolved. Service Attention This issue is responsible by Azure service team. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 30, 2023
@ghost
Copy link

ghost commented Mar 30, 2023

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @bkolant-MSFT, @sajeetharan, @pjohari-ms.

Issue Details
  • Package Name: @azure/cosmos
  • Package Version: 3.17.1
  • Operating system: MacOS and Azure App Services
  • nodejs
    • version: 14 and 16
  • browser
    • name/version:
  • typescript
    • version: 4.8.4
  • Is the bug related to documentation in

Describe the bug
After investigation we found that there is as any issue with the fetchNext() method that we are using, when we only expect one database result.

Sometimes the first call to fetchNext() will return an empty array of resources with hasMoreResults = true. In order to get the first record in this situation you have to call fetchNext() multiple times until you get a result, or hasMoreResults becomes comes false.

On the other hand fetchAll() will call fetchNext() multiple times until all the results are retrieved. (There are no more results.)

So we are switching all of the findOne() and similar methods over to use fetchAll() to avoid this problem.

To Reproduce
Steps to reproduce the behavior:

  1. Insert a bunch of records into a container, with different partition keys.
  2. Try to query for a single document with a unique identifier that is not the id/pk of the container. (This means that the queries will be cross partition queries.)
  3. Try Step 2 for all documents in the container, until one fails to be returned by the first call to fetchNext()
  4. This behavior will repeatable for the document identified in Step 3

Expected behavior
The first call to fetchNext() always returns the first query result.

Actual behavior
The first call to fetchNext() does not always return the first result.

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

Additional context
Add any other context about the problem here.

Author: paulsmithkc
Assignees: sajeetharan, abkolant-MSFT
Labels:

bug, customer-reported, Client, Cosmos, Service Attention

Milestone: azure-cosmos jan release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

6 participants