Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.47k stars 4.8k forks source link

TableInput for single entity returns array with all entities in that partition #40960

Closed patrick11994 closed 8 months ago

patrick11994 commented 1 year ago

I am using the TableInput binding with a partionkey and a rowkey to retrieve a single entity in the table.

[Function("SomeFunction")]
public HttpResponseData Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "somefunction/{paramname}")] HttpRequestData req,
    [TableInput("someTable", "somePartition", "{paramname}")] SomeEntity someEntity)
{
    // Removed to keep it on-topic ๐Ÿ˜Š
}

This results in the error:

Cannot convert input parameter 'someEntity' to type 'Namespace.For.Entity.SomeEntity' from type 'System.String'

Now using an IEnumerable as input parameter type for the TableInput, like this:

[Function("SomeFunction")]
public HttpResponseData Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "somefunction/{paramname}")] HttpRequestData req,
    [TableInput("someTable", "somePartition", "{paramname}")] IEnumerable<SomeEntity> someEntities)
{
    // Removed to keep it on-topic ๐Ÿ˜Š
}

Results in no error, and gives me all rows back from somePartition, ignoring the row key

Even when hardcoding a row key inside the TableInput, this is still happening:

[Function("SomeFunction")]
public HttpResponseData Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "somefunction")] HttpRequestData req,
    [TableInput("someTable", "somePartition", "someRowKey")] IEnumerable<SomeEntity> someEntities)
{
    // Removed to keep it on-topic ๐Ÿ˜Š
}

This returns all rows inside somePartition, ignoring the row key.

Issue Azure/azure-functions-dotnet-worker#1233 is about the same and tells me that this should be resolved, but it is not.

Using NuGet packages:

And Azurite

thomaspb88 commented 12 months ago

I'm also experiencing this issue using

Microsoft.Azure.Functions.Worker v1.19.0 Microsoft.Azure.Functions.Worker.Extensions.Http v3.1.13 Microsoft.Azure.Functions.Worker.Extensions.Tables v1.2.1 Microsoft.Azure.Functions.Worker.Sdk v1.15.1

newntech commented 11 months ago

Same issue. `

<PackageReference Include="Microsoft.AspNetCore.Http.Connections.Common" Version="7.0.13" />
<PackageReference Include="Microsoft.Azure.Core.NewtonsoftJson" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.0-preview.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.SignalRService" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Tables" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" /> `
peramhe commented 11 months ago

I'm facing this same issue with a PowerShell based Azure Function running in Azure (runtime version 4.27.5.21549).

I have the following binding defined in function.json:

    {
      "tableName": "MyTable",
      "partitionKey": "MyPartition",
      "rowKey": "Row1",
      "connection": "MY_STORAGE_ACCOUNT_CONNECTION_STRING",
      "name": "TableEntity",
      "type": "table",
      "direction": "in"
    }

When running the function, rowKey gets ignored and all the rows from 'MyPartition' are passed as $TableEntity parameter.

surgupta-msft commented 10 months ago

The issue seems to have existed since the start of worker extension package -

"Microsoft.Azure.Functions.Worker.Extensions.Tables, Version=1.0.0"

Refer to the comment - link. Transferred it to sdk team for further investigation.

jsquire commented 10 months ago

@JoshLove-msft : Would you please take a look?

JoshLove-msft commented 9 months ago

This issue is about the isolated worker extension packages which do not live in this repo. @surgupta-msft, can you let us know why this issue was transferred from the dotnet worker repo (where the tables isolated extension lives) to the azure-sdk-for-net repo (where the host extension lives)?

jsquire commented 8 months ago

The Azure SDK team is unable to reproduce this behavior for the Microsoft.Azure.WebJobs.Extensions.Tables package; it appears to be another possible instance of the isolated worker parameter binding bug. If not that, it would be something in the isolated worker package itself. This has been transferred back to the functions host repository where the worker packages are maintained as #2320.