You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Internal] Binary Encoding: Fixes serializer for non-point operations. (#5058)
# Pull Request Template
## Description
In the current code, CosmosClient used a default version of
CosmosJsonDotNetSerializer as a propertiesSerializer which used the
ConfigurationManager.IsBinaryEncodingEnabled() to determine whether to
use binary encoding during serialization and de-serialization.
This propertiesSerializer is hooked into multiple serializers to use as
internal serializers and caused unexpected behaviors for APIs like
ReadManyItems, ChangeFeed and caused a regression.
## Type of change
There are 3 parts of the change:
- As part of this change we are introducing a binary serializer. The
default serializer will not just use `propertySerializer` but it will
check if the binary encoding flag is enabled and accordingly assign the
serializer.
- When a custom serializer is present, on the response path, no matter
what we always return the stream as Text to the serializer. If the
default serializer is used then we pass the binary stream in the
serializer.
- During some local testing, I realized that `CreateItemAsync` with
`PreTriggers` or `PostTriggers` doesn't work when binary encoding is
enabled. This is because when triggers are present in the item request
options the backend will pass the stream to the javascript engine, which
does not support binary encoded content at the moment. For long term,
since trigger operations won't be supported in the backend, avoiding the
binary encoding in such cases, will be the ideal approach. Therefore,
needed to skip using binary in such situation. For example, the below
code will fail today (before the fix in the PR) if it's used with binary
encoding:
```
ItemRequestOptions requestOptions = new ItemRequestOptions()
{
PreTriggers = new List<string>() { triggerResponse.Resource.Id },
};
Comment comment = new Comment(
Guid.NewGuid().ToString(),
"pk",
random.Next().ToString(),
"[email protected]",
"This document is intended for binary encoding.");
ItemResponse<Comment> writeResponse = await container.CreateItemAsync<Comment>(
item: comment,
partitionKey: new Cosmos.PartitionKey(comment.pk),
requestOptions: requestOptions
);
```
Please delete options that are not relevant.
- [X] Bug fix (non-breaking change which fixes an issue)
## Closing issues
To automatically close an issue: closes#5043
---------
Co-authored-by: Kiran Kumar Kolli <[email protected]>
Co-authored-by: Debdatta Kunda <[email protected]>
Co-authored-by: Debdatta Kunda <[email protected]>
Copy file name to clipboardExpand all lines: Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,8 @@ public class CosmosClientOptions
74
74
privateIWebProxywebProxy;
75
75
privateFunc<HttpClient>httpClientFactory;
76
76
privatestringapplicationName;
77
-
privateIFaultInjectorfaultInjector;
77
+
privateIFaultInjectorfaultInjector;
78
+
privateboolisCustomSerializerProvided;
78
79
79
80
/// <summary>
80
81
/// Creates a new CosmosClientOptions
@@ -624,7 +625,8 @@ public CosmosSerializer Serializer
624
625
thrownewArgumentException(
625
626
$"{nameof(this.Serializer)} is not compatible with {nameof(this.SerializerOptions)} or {nameof(this.UseSystemTextJsonSerializerWithOptions)}. Only one can be set. ");
0 commit comments