question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't Set Value to Null using Patch Operation

See original GitHub issue

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

Describe the bug When using PatchOperation.Replace, I am unable to set value to null. I have tried both null and new 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 type object?. createNullValue() creates the JProperty 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:

{
 "id": "adfda-asdgasd-adsfasdf",
  "partition_key": "aigeqwg-iuiou-qryqer",
  "description": null
}

Actual behavior Description property is unchanged.

Environment summary SDK Version: 3.32.0 OS Version: Windows 10

Additional context Nothing additional to add.

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brandonsmith86commented, Jun 30, 2023

@aavasthy Found an issue in my logic. Updating versions does resolve it. Thank you!

1reaction
brandonsmith86commented, Jun 29, 2023

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 object? type.

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));
Read more comments on GitHub >

github_iconTop Results From Across the Web

PatchOperation.Set cannot handle null values · Issue #2931
Set throws ArgumentNullException when value is null. To Reproduce await container... ... Can't Set Value to Null using Patch Operation #3959.
Read more >
Cosmos DB "Partial Update"/Patch, cant set new property ...
The problem is, that it throws at the PatchOperation-Add() if I set second parameter to null (with message "Value cannot be null"). I...
Read more >
Partial Update (PATCH) With Explicit Null Values | Konrad Drozd
In this article, I will show you, how to perform a partial update with explicit values using JsonNullable and mapstruct.
Read more >
How to unset a field with a PATCH request?
Null is a valid value and undefined is not a valid json value (but the deserializer accepts it), so it is logically not...
Read more >
How to Set One or More Fields of an Object to Null Using ...
This article explains how to set one or more fields of an object to null using the Update or Upsert operation of Salesforce...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found