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

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

fetchNext() does not return the first result #23771

paulsmithkc opened this issue Nov 9, 2022 · 7 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 Workflow: 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 Workflow: 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 Workflow: This issue needs the team to triage. labels Nov 9, 2022
@ghost ghost removed the needs-triage Workflow: 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 Workflow: This issue needs the team to triage. label Nov 9, 2022
@sajeetharan sajeetharan moved this to Ready to start in @azure/cosmos Project Nov 10, 2022
@abkolant-MSFT abkolant-MSFT moved this from Ready to start to In Progress in @azure/cosmos Project Nov 14, 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!

@sajeetharan sajeetharan moved this from In Progress to Done in @azure/cosmos Project Dec 16, 2022
@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.

@sajeetharan sajeetharan moved this from Done to In Progress in @azure/cosmos Project Jan 3, 2023
@v1k1 v1k1 reopened this Jan 17, 2023
@v1k1
Copy link
Contributor

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 Workflow: 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

@abkolant-MSFT abkolant-MSFT moved this from In Progress to Done in @azure/cosmos Project Apr 4, 2023
Copy link

github-actions bot commented Nov 8, 2024

Hi @paulsmithkc, we deeply appreciate your input into this project. Regrettably, this issue has remained unresolved for over 2 years and inactive for 30 days, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 Workflow: This issue is responsible by Azure service team.
Projects
Archived in project
Development

No branches or pull requests

6 participants