PatchOperation.Set cannot handle null values
See original GitHub issueWe are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.
Describe the bug PatchOperation.Set throws ArgumentNullException when value is null.
To Reproduce await container.PatchItemAsync<T>(id, PartitionKey.None, new List<PatchOperation> { PatchOperation.Set<string>(“/name”, null) });
Expected behavior Value should be set to null.
Actual behavior
System.ArgumentNullException: Value cannot be null. (Parameter ‘value’) at Microsoft.Azure.Cosmos.PatchOperationCore`1…ctor(PatchOperationType operationType, String path, T value) at Microsoft.Azure.Cosmos.PatchOperation.Set[T](String path, T value)
Environment summary SDK Version: 3.23.0 OS Version (e.g. Windows, Linux, MacOSX) Windows 11
Additional context According to @sajeetharan (https://stackoverflow.com/a/70194090/22092), this seems to be a known issue but I couldn’t find any matching issue in github.
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (9 by maintainers)
Top GitHub Comments
This works for me.
Instead of using null I just create a JProperty with the value null. And use that value.
private JToken NullValue { get { return new JProperty("nullValue", null).Value; } }
And use it like thisoperations.Add(PatchOperation.Set("\customer", value ?? NullValue));
Hi, I have a workaround as below which could resolve your problem:
My thought is that here we shouldn’t add null checks for value.