-
Notifications
You must be signed in to change notification settings - Fork 494
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
Can't Set Value to Null using Patch Operation #3959
Comments
@brandonsmith86 I am able to replace the property value with null using the latest SDK version https://www.nuget.org/packages/Microsoft.Azure.Cosmos. You would need to explicitly specify the type argument for 'Replace' method. Code example:
Please let me know if you run into any issues with this. |
Hi @aavasthy. Thank you for spending the time to reproduce. Do you think my problem is version, or lack of generic type? With my current implementation, I would not be able to supply type as I'm using reflection to get the value, which returns Edit: I suppose I can do something like this. I'll check tomorrow if this resolves it (in addition to updating to latest version). patchOperations.Add(propValue == null // use generic version of PatchOperation.Replace if value is null
? PatchOperation.Replace<string?>($"/{cosmosPropName}", null)
: PatchOperation.Replace($"/{cosmosPropName}", propValue)); |
@brandonsmith86 Please try with the latest version because I don't see SDK Version: 3.32.0 in here https://www.nuget.org/packages/Microsoft.Azure.Cosmos.
|
@aavasthy Decided to give it a try today. The code that I posted above did not clear out the property. Very curious... |
@aavasthy Found an issue in my logic. Updating versions does resolve it. Thank you! |
Closing this issue since updating fixed my issue. |
Describe the bug
When using
PatchOperation.Replace
, I am unable to set value to null. I have tried bothnull
andnew JProperty(propName, null).Value
. The latter was attempted due to recommendation in #2931.To Reproduce
This is the code used to create
PatchOperation
:PatchOperation.Replace($"/{cosmosPropName}", propValue ?? createNullValue(cosmosPropName))
.propValue
is typeobject?
.createNullValue()
creates theJProperty
mentioned in the description.Expected behavior
I would expect the property to be set to null value. Below example assumes description property is being set to null:
Actual behavior
Description property is unchanged.
Environment summary
SDK Version: 3.32.0
OS Version: Windows 10
Additional context
Nothing additional to add.
The text was updated successfully, but these errors were encountered: