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

CosmosDBTrigger Alters DateTimeOffset Format in Azure Function Isolated Process #898

Open
JarFrank opened this issue Jun 14, 2024 · 2 comments

Comments

@JarFrank
Copy link

I'm encountering an issue with the CosmosDBTrigger in an Azure Function using the isolated process model. When documents are triggered by changes in a Cosmos DB collection, the CosmosDBTrigger seems to alter the format of DateTimeOffset fields in the JSON payload.

Repro steps

Set up an Azure Function with a CosmosDBTrigger to monitor changes in a Cosmos DB collection.

public class TriggerFunction(ILoggerFactory loggerFactory)
{
    private readonly ILogger _logger = loggerFactory.CreateLogger<Function>();

    [Function("TriggerFunction")]
    public void Run([CosmosDBTrigger(
        databaseName: "my-database",
        containerName: "my-container",
        Connection = "ConnectionStrings:Cosmos",
        LeaseContainerName = "leases",
        StartFromBeginning = true,
        LeaseContainerPrefix = "my-",
        CreateLeaseContainerIfNotExists = true)] string input)
    {
        _logger.LogInformation("Migration {input}", input);
    }
}
  1. Insert a document into the Cosmos DB collection:
{
    "id": "1",
    "TransactionDate": "2023-07-04T12:00:00+00:00"
}
  1. The CosmosDBTrigger function receives:
{
    "id": "1",
    "TransactionDate": "2023-07-04T14:00:00+02:00"
}

Expected behavior

The CosmosDBTrigger should pass the document as-is without altering the format or values.

Actual behavior

The date field in the JSON document is modified.

Known workarounds

none.

Related information

  • Azure Function 4.x - isolated process
  • Language C#
  • Packages:
    Microsoft.Azure.Functions.Worker, Version="1.22.0"
    Microsoft.Azure.Functions.Worker.Extensions.CosmosDB, Version="4.9.0"
    Microsoft.Azure.Functions.Worker.Extensions.Http, Version="3.2.0"
    Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore, Version="1.3.2"
    Microsoft.Azure.Functions.Worker.Sdk, Version="1.17.2"
    Microsoft.ApplicationInsights.WorkerService, Version="2.22.0"
    Microsoft.Azure.Functions.Worker.ApplicationInsights, Version="1.2.0"
@ealsur
Copy link
Member

ealsur commented Jun 20, 2024

This seems related to Date Time Handling. When the raw JSON comes from the service, in order to bind it to string (the type on your trigger), it gets serialized through Newtonsoft.Json (the default engine for Cosmos DB SDK).

Newtonsoft.Json has a default Json serialization behavior for dates which does DateTime conversion with timezones.

References:

You can probably set it on the global JsonSerializerSettings. I am not an expert in the Isolated Process world though to know if that will work.

@ealsur
Copy link
Member

ealsur commented Jul 9, 2024

Also, the correct repo is https://github.com/Azure/azure-functions-dotnet-worker/issues

The nuget you are using is not from this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants