PatchOperation.Add throws an exception if the value is null. #3829
Labels
bug
Something isn't working
needs-more-information
patch
No contract changes. (Bug fixes, doc bugs, etc.)
Describe the bug
Unable to
PatchOperation.Add("/path", value)
when the value is null.Same as issue 2931 #2931, but when doing an .Add
To Reproduce
string? svar = null;
await container.PatchItemAsync(id, partitionKey, new List { PatchOperation.Add("/name", svar) });
Expected behavior
The value should be allowed to be null, and the JSON document in the container should get a "null" value for /name.
Actual behavior
System.Private.CoreLib: Exception while executing function: ReadDataFromCosmosDb. Anonymously Hosted DynamicMethods Assembly: The type arguments for method 'Microsoft.Azure.Cosmos.PatchOperation.Add(string, T)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Environment summary
SDK Version: 3.32.3
OS Version (e.g. Windows, Linux, MacOSX) MacOSX
Additional context
If I try to write:
PatchOperation.Add("/name", null)
then I get a compile error (same text as "actual behavior" above)
Similar to issue 2931 but that was for .Set. I think all of the patch methods should accept a null value since the JSON document supports nulls and it's reasonable to expect a POCO to have a null value.
The same JToken workaround from post 2931 works for .Add
The text was updated successfully, but these errors were encountered: