azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

Node.js Azure function input binding for Table storage ignores rowKey

Open yohny opened this issue 1 year ago • 11 comments

I have a simple Node.js Azure function (runtime v4) with input binding for Azure Table storage as follows:

import { app, HttpRequest, HttpResponseInit, InvocationContext, input } from "@azure/functions";

const tableInput = input.table({
    tableName: 'Person',
    partitionKey: 'Test',
    rowKey: '{key}',
    connection: 'AzureWebJobsStorage',
});

export async function readTable(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    context.log(`Http function processed request for url "${request.url}"`);

    const tableData = context.extraInputs.get(tableInput)

    return { jsonBody: tableData };
};

app.http('readTable', {
    methods: ['GET'],
    route: 'read/{key}',
    extraInputs: [tableInput],
    authLevel: 'anonymous',
    handler: readTable
});

The result of this function is however all the rows in Person table with Test partition key, instead of just one (or none) with given rowKey.

The behaviour is the same localy (with Azurite as storage emulator) and when deployed to Azure.

Node.js v20, @azure/functions v4.5.0

yohny avatar Aug 01 '24 15:08 yohny

Same issue here

Node.js v18.20.4 @azure/functions v4.5.1

tojo6797 avatar Sep 19 '24 15:09 tojo6797

Hello @yohny, Thanks for reporting. This happens because the Node.js v4 model doesn’t fully support single-entity table input binding with rowKey. It defaults to fetching all rows with the given partitionKey. To fetch a specific entity, please try using the Azure Tables SDK directly in your function.

raushan2998 avatar May 08 '25 11:05 raushan2998

/bot not-stale

yohny avatar May 12 '25 16:05 yohny

Hello @yohny,

Just a follow up regarding feedback on the above response provided from our side.

raushan2998 avatar May 13 '25 07:05 raushan2998

Retrieving single record using the Azure Tables SDK works as expected. But I believe this isuse is still valid, as retrieval using binding does not work as expected. Or did I misunderstand something?

yohny avatar May 13 '25 10:05 yohny

Thanks for confirming that the SDK works as expected. You’re not misunderstanding. In the current Node.js v4 programming model, the binding only filters by partitionKey, even if rowKey is specified. This is a known limitation, not the intended behavior for single-entity access.

raushan2998 avatar May 14 '25 10:05 raushan2998

/bot not-stale

yohny avatar May 20 '25 07:05 yohny

Hi @yohny,

Just a follow up regarding feedback on the above response provided from our side.

raushan2998 avatar May 20 '25 09:05 raushan2998

feedback to what? there was no additional info requested, or am I missing something?

yohny avatar May 20 '25 09:05 yohny

@yohny, Apologies for the confusion earlier.

Just to clarify, In the current Node.js v4 programming model, even when both partitionKey and rowKey are set in the Table input binding, only the partitionKey is used for filtering. That’s why you’re seeing all rows with the Test partition, the rowKey is unfortunately ignored. This is a known limitation. Using the Azure Tables SDK, as you’ve done, is currently the most reliable way to retrieve a single record using both keys.

Let me know if you’d like me to pass this as product feedback on your behalf.

raushan2998 avatar May 20 '25 14:05 raushan2998

sure, you can pass it as product feedback anyway, I would like to keep this issue open until its fixed

yohny avatar May 20 '25 16:05 yohny