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

PatchOperation.Add throws an exception if the value is null. #3829

Closed
danieldespainTLS opened this issue Apr 27, 2023 · 3 comments
Closed

PatchOperation.Add throws an exception if the value is null. #3829

danieldespainTLS opened this issue Apr 27, 2023 · 3 comments
Labels
bug Something isn't working needs-more-information patch No contract changes. (Bug fixes, doc bugs, etc.)

Comments

@danieldespainTLS
Copy link

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

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

@ealsur ealsur added bug Something isn't working patch No contract changes. (Bug fixes, doc bugs, etc.) and removed needs-investigation labels Apr 28, 2023
@ealsur
Copy link
Member

ealsur commented Apr 28, 2023

@aavasthy could you take a look? It seems we missed adding support for this on Add and Replace operations

@ealsur ealsur moved this to Approved in Azure Cosmos SDKs Apr 28, 2023
@aavasthy
Copy link
Contributor

@danieldespainTLS The error message you encountered isn't pointing to ArgumentNullException but it suggests that the type of the 'svar' variable cannot be inferred by the compiler. Please try to explicitly specify the type argument for the 'Add' method of the PatchOperation.

Updated code:

string? svar = null;
await container.PatchItemAsync(id, partitionKey, new List { PatchOperation.Add<string>("/name", svar)});

@ghost
Copy link

ghost commented May 29, 2023

@danieldespainTLS this issue requires more information for the team to be able to help. In case this information is available, please add it and re-open the Issue.

@ghost ghost closed this as completed May 29, 2023
@github-project-automation github-project-automation bot moved this from Approved to Done in Azure Cosmos SDKs May 29, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-more-information patch No contract changes. (Bug fixes, doc bugs, etc.)
Projects
Status: Done
Development

No branches or pull requests

3 participants