IfMatchEtag on ReadItemAsync not honoured
See original GitHub issueDescribe the bug
IfMatchEtag
does not appear to be working as described.
The documentation states:
Most commonly used with the Delete* and Replace* methods of Container such as ReplaceItemAsync<T>(T, String, Nullable<PartitionKey>, ItemRequestOptions, CancellationToken) but can be used with other methods like ReadItemAsync<T>(String, PartitionKey, ItemRequestOptions, CancellationToken) for caching scenarios.
I have witnessed this working previously on an UpsertItem call as well as a Replace call.
However, it does not appear to work on ReadItemAsync. This can be verified relatively simply.
To Reproduce
var etag = "....";
var result = await container.ReadItemAsync<T>(id, new PartitionKey(partitionKey), new ItemRequestOptions {
IfMatchEtag = etag
});
if (result.ETag != etag) {
throw new Exception("Cosmos returned document with mismatched ETag");
}
Expected behavior
I would expect a CosmosException
with either a PreconditionFailed
or Conflict
(although the latter is not so semantic) status.
Actual behavior
The item is returned without issue, with a different ETag than what was presented. Status Code is OK
.
Environment summary SDK Version: .NET 3.35.1 OS Version: Mac OSX, also verified on Linux (App Service), and Windows (another dev machine)
Additional context This can be reproduced in the Javascript SDK.
Issue Analytics
- State:
- Created 2 months ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Thanks for confirming. I’ll see if I can get confirmation from the service team and if Reads are not expected to work, we’ll update the documentation.
I have attempted this with a real (previous) ETag from a document and with a fake as per my reproduction (
...
) and received the same result. The document was read successfully from Cosmos.From your scenario list, scenario 4 is what is broken and what I have been trying to demonstrate. The 412 result is not returned, instead, it reads the document correctly.
Again this can be verified very simply using the reproduction code. The key bit is here, which throws: