Skip to content

Commit

Permalink
Fix repository TryFindByIdAsync (#416)
Browse files Browse the repository at this point in the history
### Motivation and Context
Repository TryFindByIdAsync would not try to find anything if no
callback was passed to it, hence always returning true, even when no
entries were found!

### Description
Always doing a true search because executing any callback with the
result.

### Contribution Checklist
- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [Contribution
Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
  • Loading branch information
glahaye authored Sep 28, 2023
1 parent 5cd6ac0 commit 3c8dab3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion webapi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static async Task Main(string[] args)
.RequireAuthorization();
app.MapHealthChecks("/healthz");

// Add CopilotChat hub for real time communication
// Add Chat Copilot hub for real time communication
app.MapHub<MessageRelayHub>("/messageRelayHub");

// Enable Swagger for development environments.
Expand Down
7 changes: 5 additions & 2 deletions webapi/Storage/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Task CreateAsync(T entity)
{
if (string.IsNullOrWhiteSpace(entity.Id))
{
throw new ArgumentOutOfRangeException(nameof(entity.Id), "Entity Id cannot be null or empty.");
throw new ArgumentOutOfRangeException(nameof(entity.Id), "Entity ID cannot be null or empty.");
}

return this.StorageContext.CreateAsync(entity);
Expand All @@ -52,7 +52,10 @@ public async Task<bool> TryFindByIdAsync(string id, string? partition = null, Ac
{
try
{
callback?.Invoke(await this.FindByIdAsync(id, partition ?? id));
T? found = await this.FindByIdAsync(id, partition ?? id);

callback?.Invoke(found);

return true;
}
catch (Exception ex) when (ex is ArgumentOutOfRangeException || ex is KeyNotFoundException)
Expand Down

0 comments on commit 3c8dab3

Please sign in to comment.