Azure-cosmos-dotnet-v3: Null values are ignored in 3.0.0.10-preview

Created on 30 May 2019  路  4Comments  路  Source: Azure/azure-cosmos-dotnet-v3

In version 3.0.0.9-preview we could create document with null values and they would be inserted as null in Cosmos DB.

Now in 3.0.0.10-preview those values are ignored, so queries that looks for these values are broken.

Ex: Select * from c where c.Property = null now returns no documents since c.Property is undefined and not null.

Required for GA bug

Most helpful comment

Here is a really simple program that inserts a document in Cosmos.

using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

namespace ConsoleApp1
{
    internal static class Program
    {
        private const string Endpoint = "<Put endpoint here>";
        private const string AuthKey = "<Put auth key here>";

        private static async Task Main(string[] args)
        {
            var cosmosClient = new CosmosClientBuilder(Endpoint, AuthKey)
                .UseConnectionModeDirect()
                .Build();

            var container = cosmosClient.Databases["<Database name>"].Containers["<Container name>"];

            dynamic document = new
            {
                id = "1234",
                Prop1 = default(string),
                PartitionKey = "1234"
            };

            await container.Items.UpsertItemAsync(document.PartitionKey, document);
        }
    }
}

When I run it with 3.0.0.10-preview, I get the following in Cosmos

{
    "id": "1234",
    "PartitionKey": "1234",
    "_rid": "UJxeAN+LVrgnJwAAAAAAAw==",
    "_self": "dbs/UJxeAA==/colls/UJxeAN+LVrg=/docs/UJxeAN+LVrgnJwAAAAAAAw==/",
    "_etag": "\"020052cd-0000-0a00-0000-5cf03c3f0000\"",
    "_attachments": "attachments/",
    "_ts": 1559247935
}

When I run it with 3.0.0.9-preview, I get the following in Cosmos

{
    "id": "1234",
    "Prop1": null,
    "PartitionKey": "1234",
    "_rid": "UJxeAN+LVrgnJwAAAAAAAw==",
    "_self": "dbs/UJxeAA==/colls/UJxeAN+LVrg=/docs/UJxeAN+LVrgnJwAAAAAAAw==/",
    "_etag": "\"020055cd-0000-0a00-0000-5cf03ccb0000\"",
    "_attachments": "attachments/",
    "_ts": 1559248075
}

As you can see Prop1 is removed when using 3.0.0.10-preview.

All 4 comments

@jriouxrandstadca The default json serializer has these options: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/CosmosJsonSerializerCore.cs#L17

It doesn't seem to have changed. Do you have a repro that we can use with 3.0.0.9-preview and 3.0.0.10-preview and compare results?

Here is a really simple program that inserts a document in Cosmos.

using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

namespace ConsoleApp1
{
    internal static class Program
    {
        private const string Endpoint = "<Put endpoint here>";
        private const string AuthKey = "<Put auth key here>";

        private static async Task Main(string[] args)
        {
            var cosmosClient = new CosmosClientBuilder(Endpoint, AuthKey)
                .UseConnectionModeDirect()
                .Build();

            var container = cosmosClient.Databases["<Database name>"].Containers["<Container name>"];

            dynamic document = new
            {
                id = "1234",
                Prop1 = default(string),
                PartitionKey = "1234"
            };

            await container.Items.UpsertItemAsync(document.PartitionKey, document);
        }
    }
}

When I run it with 3.0.0.10-preview, I get the following in Cosmos

{
    "id": "1234",
    "PartitionKey": "1234",
    "_rid": "UJxeAN+LVrgnJwAAAAAAAw==",
    "_self": "dbs/UJxeAA==/colls/UJxeAN+LVrg=/docs/UJxeAN+LVrgnJwAAAAAAAw==/",
    "_etag": "\"020052cd-0000-0a00-0000-5cf03c3f0000\"",
    "_attachments": "attachments/",
    "_ts": 1559247935
}

When I run it with 3.0.0.9-preview, I get the following in Cosmos

{
    "id": "1234",
    "Prop1": null,
    "PartitionKey": "1234",
    "_rid": "UJxeAN+LVrgnJwAAAAAAAw==",
    "_self": "dbs/UJxeAA==/colls/UJxeAN+LVrg=/docs/UJxeAN+LVrgnJwAAAAAAAw==/",
    "_etag": "\"020055cd-0000-0a00-0000-5cf03ccb0000\"",
    "_attachments": "attachments/",
    "_ts": 1559248075
}

As you can see Prop1 is removed when using 3.0.0.10-preview.

@j82w & @simplynaveen20 is this addressed now?

Fix is shipped with 3.0.0.18-preview.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gegoodwin picture gegoodwin  路  7Comments

nulltoken picture nulltoken  路  3Comments

thomaslevesque picture thomaslevesque  路  7Comments

lukasz-pyrzyk picture lukasz-pyrzyk  路  3Comments

JeremyLikness picture JeremyLikness  路  7Comments