Skip to content

Commit

Permalink
Empty query results does not throw
Browse files Browse the repository at this point in the history
We now check for 404 since that's the expected response, which we can consider as an empty result set.
  • Loading branch information
kzu committed Jul 25, 2023
1 parent 2c81434 commit 087b2d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/TableStorage/TableRepositoryQuery`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public async IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellati
var response = await Http.Client.SendAsync(request);
while (true)
{
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
yield break;

response.EnsureSuccessStatusCode();

var json = await response.Content.ReadAsStringAsync();
Expand Down
15 changes: 15 additions & 0 deletions src/Tests/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ public async Task CanFilterByEntityRowKey()
}
}

[Fact]
public async Task EmptyQueryDoesNotFail()
{
var account = CloudStorageAccount.DevelopmentStorageAccount;
var repo = TableRepository.Create(account, TableName());

var query = from book in repo.CreateQuery()
where
book.PartitionKey == "Rick Riordan" &&
book.RowKey.CompareTo("97814231") >= 0 &&
book.RowKey.CompareTo("97814232") < 0
select book;

Assert.Empty((await query.AsAsyncEnumerable().ToListAsync()));
}

async Task LoadBooksAsync(ITableStorage<Book> books)
{
Expand Down

0 comments on commit 087b2d9

Please sign in to comment.