question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListDocumentsAsync inconsistent with results

See original GitHub issue

OS: Linux Mint 19.2 .NET version: 2,2 Package version: Google.Apis.Firestore.v1beta1

I have an ASP.NET Core application where I have an entity that points to a sub-collection of entities.

My code looked like this:

var ret = client.Collection(path).ListDocumentsAsync();
await ret.ForEachAsync(async x =>
{
    var y = await x.GetSnapshotAsync();
    list.Add(y.ConvertTo<Job>());
});
return list;

Despite having a record in said path, I kept getting an empty list returned. Only when I went to debug the issue - either by stepping through the repository containing this code or through another part of the stack - did it actually return anything.

Ultimately the fix for this (for me) was to use GetSnapshotAsync method which returns everything (what I wanted in the first place), but I thought I’d bring it up in case anyone else ran into something similar.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
jskeetcommented, Aug 21, 2019

Okay, I understand now. I can reproduce it more simply with my original code, but from the “Now list the contents comment” use:

// Now list the contents
var docs = collection.ListDocumentsAsync();
int count = 0;
await docs.ForEachAsync(async doc =>
{
    await doc.GetSnapshotAsync();
    count++;
});
Console.WriteLine($"Count immediately afterwards: {count}");
for (int i = 0; i < 5; i++)
{
    await Task.Delay(500);
    Console.WriteLine($"Count after a pause: {count}");
}

The problem is that ForEachAsync accepts Action<T> delegates, not Func<T, Task> delegates. It waits for the action to complete, but in the case of an async action, that doesn’t mean the whole lambda expression has completed.

It’ll be much easier to handle this in C# 8 with built-in language constructs - although we’re going to need a whole new major version to support that, annoyingly 😦

If you convert the sequence to a list using var references = await docs.ToList(); and then iterate over the list, that’s probably the best way of doing what you were after. You could potentially write your own ForEachAsync extension method if you wanted, instead.

I’m going to close this now as it’s not really a Firestore issue - do let me know if you want any more details.

0reactions
elvogelcommented, Aug 21, 2019

Not a problem. You’ve given me more than enough workarounds to continue development, so I’ll go ahead and make the changes I need to work around the issue. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Resolve Sync Conflicts with Sync Center
Resolving sync conflicts · 1. Open the Start Menu and select Control Panel. · 2. Open Sync Center · 3. Select View Sync...
Read more >
Inconsistency in %complete with sync of tasks from Project ...
I have a Project 2013 project plan I'm synchronizing with a task list in SharePoint 2013. The %complete does not consistently synchronize ...
Read more >
Some documents were not synced at initial sync. After ...
Device 1 signs in with account, documents are created and synced. Device 2 signs in with same account, documents are pulled down. Then...
Read more >
How to sync only some but not all folders using sync_list
Documents Creating local directory: Documents/subfolder WARNING: OneDrive API inconsistency - this file does not have any hash: ...
Read more >
Tips for syncing items in IBM Content Navigator
If a document gets out of sync with the content that is stored in the repository, you can resolve the sync conflict by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found