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

Cosmos: Find / FindAsync missing key throws exception instead of returning null #25115

Closed
cmeyertons opened this issue Jun 17, 2021 · 1 comment · Fixed by #25887
Closed

Cosmos: Find / FindAsync missing key throws exception instead of returning null #25115

cmeyertons opened this issue Jun 17, 2021 · 1 comment · Fixed by #25887
Assignees
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@cmeyertons
Copy link

File a bug

invoking FindAsync on a missing value is throwing a 404 exception instead of returning null, as the XML documentation on FindAsync states.

_context.ApiResponses.FindAsync(key)

documentation:

// Summary:
//     Finds an entity with the given primary key values. If an entity with the given
//     primary key values is being tracked by the context, then it is returned immediately
//     without making a request to the database. Otherwise, a query is made to the database
//     for an entity with the given primary key values and this entity, if found, is
//     attached to the context and returned. If no entity is found, then null is returned.
//
// Parameters:
//   keyValues:
//     The values of the primary key for the entity to be found.
//
// Returns:
//     The entity found, or null.
public virtual ValueTask<TEntity> FindAsync([CanBeNullAttribute] params object[] keyValues);

exception:

Microsoft.Azure.Cosmos.CosmosException
  HResult=0x80131500
  Message=Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: 7e0e73f0-cb8a-4517-99a8-8ce8be3cd797; Reason: ({
  "Errors": [
    "Resource Not Found. Learn more: https://aka.ms/cosmosdb-tsg-not-found"
  ]
});
  Source=Microsoft.Azure.Cosmos.Client
  StackTrace:
   at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode()
   at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.JObjectFromReadItemResponseMessage(ResponseMessage responseMessage)
   at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.<ExecuteReadItemAsync>d__40.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable`1.Enumerator.<MoveNextAsync>d__18.MoveNext()
...

EF Core version: 5.0.7
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: (e.g. .NET 5.0)
Operating system: Windows 10
IDE: Visual Studio 2019 16.10

@roji
Copy link
Member

roji commented Sep 6, 2021

Poaching

@roji roji changed the title Cosmos Provider - Find / FindAsync missing key throws exception instead of returning null Cosmos: Find / FindAsync missing key throws exception instead of returning null Sep 6, 2021
roji added a commit that referenced this issue Sep 6, 2021
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Sep 6, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc2 Sep 8, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc2, 6.0.0 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants