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

DateOnly and TimeOnly parameter binding throws exception #2714

Open
JensSchadron opened this issue Sep 16, 2024 · 2 comments
Open

DateOnly and TimeOnly parameter binding throws exception #2714

JensSchadron opened this issue Sep 16, 2024 · 2 comments
Labels
potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug

Comments

@JensSchadron
Copy link

JensSchadron commented Sep 16, 2024

Description

When using a DateOnly or TimeOnly parameter binding in a function (for example when extracting from the route of a HTTP Trigger or as a parameter in a SignalR binding), the function invocator throws the following exception respectively.

DateOnly

Microsoft.Azure.Functions.Worker.FunctionInputConverterException: Error converting 1 input parameters for Function 'DateOnlyTest': Cannot convert input parameter 'date' to type 'System.DateOnly' from type 'System.String'. Error:System.Text.Json.JsonException: '-' is an invalid end of a number. Expected a delimiter. Path: $ | LineNumber: 0 | BytePositionInLine: 4.
 ---> System.Text.Json.JsonReaderException: '-' is an invalid end of a number. Expected a delimiter. LineNumber: 0 | BytePositionInLine: 4.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.TryGetNumber(ReadOnlySpan`1 data, Int32& consumed)
   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObjectAsync(Stream utf8Json, CancellationToken cancellationToken)
   at Microsoft.Azure.Functions.Worker.Converters.JsonPocoConverter.GetConversionResultFromDeserialization(Byte[] bytes, Type type) in D:\a\_work\1\s\src\DotNetWorker.Core\Converters\JsonPocoConverter.cs:line 66
   at Microsoft.Azure.Functions.Worker.Context.Features.DefaultFunctionInputBindingFeature.BindFunctionInputAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Context\Features\DefaultFunctionInputBindingFeature.cs:line 97
   at SignalRSandbox.Functions.DirectFunctionExecutor.ExecuteAsync(FunctionContext context)

TimeOnly

Microsoft.Azure.Functions.Worker.FunctionInputConverterException: Error converting 1 input parameters for Function 'TimeOnlyTest': Cannot convert input parameter 'time' to type 'System.TimeOnly' from type 'System.String'. Error:System.Text.Json.JsonException: Invalid leading zero before '9'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
 ---> System.Text.Json.JsonReaderException: Invalid leading zero before '9'. LineNumber: 0 | BytePositionInLine: 1.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ConsumeZero(ReadOnlySpan`1& data, Int32& i)
   at System.Text.Json.Utf8JsonReader.TryGetNumber(ReadOnlySpan`1 data, Int32& consumed)
   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObjectAsync(Stream utf8Json, CancellationToken cancellationToken)
   at Microsoft.Azure.Functions.Worker.Converters.JsonPocoConverter.GetConversionResultFromDeserialization(Byte[] bytes, Type type) in D:\a\_work\1\s\src\DotNetWorker.Core\Converters\JsonPocoConverter.cs:line 66
   at Microsoft.Azure.Functions.Worker.Context.Features.DefaultFunctionInputBindingFeature.BindFunctionInputAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Context\Features\DefaultFunctionInputBindingFeature.cs:line 97
   at SignalRSandbox.Functions.DirectFunctionExecutor.ExecuteAsync(FunctionContext context)

Things of note:
I'm using the Asp.NET Core integration for this test.
The parameter binding however works for a DateTime parameter, as can be seen in the sample code below.

Hereby also the list of used libraries (all are latest version at the time of writing)

<FrameworkReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.SignalRService" Version="1.14.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.OpenTelemetry" Version="1.0.0-preview1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.4" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />

Steps to reproduce

Test functions being used.

[Function("DateTimeTest")]
public HttpResponseData DateTimeTest(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "datetime/{dateTime}")] HttpRequestData req,
    DateTime dateTime)
{
    _logger.LogInformation("Received datetime: {DateTime}", dateTime);

    return req.CreateResponse(HttpStatusCode.NoContent);
}

[Function("DateOnlyTest")]
public HttpResponseData DateOnlyTest(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "dateonly/{date}")] HttpRequestData req,
    DateOnly date)
{
    _logger.LogInformation("Received date: {Date}", date);

    return req.CreateResponse(HttpStatusCode.NoContent);
}

[Function("TimeOnlyTest")]
public HttpResponseData TimeOnlyTest(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "timeonly/{time}")] HttpRequestData req,
    TimeOnly time)
{
    _logger.LogInformation("Received time: {Time}", time);

    return req.CreateResponse(HttpStatusCode.NoContent);
}

And the HTTP file being used to invoke the functions above.

### GET request for working datetime test

GET http://localhost:7071/api/datetime/2024-09-16T09:15:40

### GET request for broken dateonly test

GET http://localhost:7071/api/dateonly/2024-09-16

### GET request for broken timeonly test

GET http://localhost:7071/api/timeonly/09:15:40
@JensSchadron JensSchadron added the potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug label Sep 16, 2024
@kshyju
Copy link
Member

kshyju commented Sep 18, 2024

We don't support it today. It was part of the original PR, but the team collectively decided to drop the support for those types at that time, so a later iteration removed it.

16cc142

@JensSchadron
Copy link
Author

Given that it was added (and subsequently removed) almost 2,5 years ago, are there any plans for it to be re-added in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants