azure-functions-dotnet-worker: Missing Table Binding
There doesn’t seem to be a way to bind to a table. Previously there was the TableAttribute in the Microsoft.Azure.WebJobs.Extensions.Storage assembly that allowed direct access to an Azure Table.
Is there another way to achieve this? When using the TableInputAttribute in the following way
[Function("Bands")]
public async Task<HttpResponseData> Execute(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req,
[TableInput("Requests", Connection = "AzureWebJobsStorage")] CloudTable table,
FunctionContext executionContext)
{
var tableEntity = new PayloadTableEntity(req.ReadAsString());
await table.ExecuteAsync(TableOperation.InsertOrMerge(tableEntity));
...
}
This exception is thrown:
System.Private.CoreLib: Exception while executing function: Functions.Bands. System.Private.CoreLib: Result:
Failure
Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting 1 input parameters
for Function 'Bands': Cannot convert input parameter 'table' to type 'Microsoft.Azure.Cosmos.Table.CloudTable' from type 'System.String'.
[2021-04-21T07:11:43.727Z] at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 70
[2021-04-21T07:11:43.729Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 37
[2021-04-21T07:11:43.731Z] at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2021-04-21T07:11:43.733Z] at Microsoft.Azure.Functions.Worker.GrpcWorker.InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) in D:\a\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 169
Stack: at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in
D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 70
[2021-04-21T07:11:43.736Z] at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 37
[2021-04-21T07:11:43.737Z] at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2021-04-21T07:11:43.740Z] at Microsoft.Azure.Functions.Worker.GrpcWorker.InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) in D:\a\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 169
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (4 by maintainers)
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Tables/1.0.0 is now a GA version, and we should have a similar package here, too. It should not be housed under Microsoft.Azure.Functions.Worker.Extensions.Storage, but rather something like Microsoft.Azure.Functions.Worker.Extensions.Tables. The readme for the Storage package (5.x version) on nuget.org should be updated to help redirect.
@asparrowhawk @MarGraz @cleferman
UPDATE: I’ve given up using
Microsoft.Azure.Functions.Worker.Extensions.Storage
now usingAzure.Data.Tables
instead. This is the new way of using Azure Table Storage.While it no longer has our beloved input binding, the API is not difficult. I’m rewriting the Azure Functions service I use to access Table Storage.
@brettsam What is the way if I would like to manipulate the binded output (or input) CloudTable’s data? Currently I got “row exist” exception if I want to “owerwrite” a row’s value. I couldn’t find any example how can I remove the old one or update an existing one.
@brettsam Can we control what kind of operation is performed when sending the data to the output? For ex on CosmosDBOutput as well as TableOutput can I define that I want the return value to be inserted/replaced? (InsertOrMerge, InsertOrReplace, Replace, Update)
@oscarvantol Many thanks for the response. That was very useful with my scenario. Lets hope the documentation for these bindings improves.
@mattchenderson - may I ask when the expected GA is for
Microsoft.Azure.Functions.Worker.Extensions.Tables
?Following up on this the Table attributes are missing from
Microsoft.Azure.Functions.Worker.Extensions.Storage
version5.0.0-beta.4
. Are there plans to add them back? And will they make use of managed identity auth? Meanwhile I believe I can useTableServiceClient
fromAzure.Data.Tables
.[TableInput]
is supported – but you cannot useCloudTable
as an parameter type. Language workers are not able to use “rich SDK types” like the in-proc .NET model was able to. We’re looking to improve this in the future.I believe that when you specify the table name only, the binding will retrieve the entire table and return it to you in this parameter (so you could use an array as your input here).
We need docs and analyzers to help with this – it’s not entirely clear what’s supported just by using the attribute itself.
Hi @asparrowhawk, you tried using [TableInput] but [TableOutput] might help you in this scenario. The following example shows how this would work, it has multi output so it is a bit bloated.
Another option if you would need to directly interact with the table, would be to use DI to inject some helper in your functions class.