Azure / Azure/azure-functions-host

Feature: Upsert Table Entity: Support Changing Existing Entities

Open
#1,663 20 comments 12 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 11h
Merged PRs (30d)
37

Description

Using Binding alone, it is not possible to modify a Table Entity.

#### Investigative information

Please provide the following:

- Timestamp: 2017-07-07T13:37:47.269
- Function App name: told-stack-demo
- Function name(s) (as appropriate): http-to-table
- Invocation ID: 8fe9fdae-6907-4cb2-9982-de43a7a4e5f2
- Region: East US 2

```
2017-07-07T13:37:47.269 Function started (Id=8fe9fdae-6907-4cb2-9982-de43a7a4e5f2)
2017-07-07T13:37:49.815 Function completed (Success, Id=8fe9fdae-6907-4cb2-9982-de43a7a4e5f2, Duration=2547ms)
2017-07-07T13:37:50.002 Exception while executing function: Functions.http-to-table. Microsoft.Azure.WebJobs.Host: Error while handling parameter _binder after function returned:. Microsoft.WindowsAzure.Storage: The specified entity already exists.
RequestId:756cc6df-0002-0065-4726-f70b5c000000
Time:2017-07-07T13:37:49.6169943Z.
```

#### Repro steps

1. Bind to a Table with 'out' direction
2. Use an existing PartitionKey and RowKey

#### Expected behavior

Provide a description of the expected behavior.

- InsertOrMerge Behavior:
- If no row exists, insert it
- If a row exists, replace column values with provided values

#### Actual behavior

Provide a description of the actual behavior observed.

```
2017-07-07T13:37:50.002 Exception while executing function: Functions.http-to-table. Microsoft.Azure.WebJobs.Host: Error while handling parameter _binder after function returned:. Microsoft.WindowsAzure.Storage: The specified entity already exists.
```

#### Known workarounds

Provide a description of any known workarounds.

- Use the Azure Storage SDK

Problems with the Workaround:

- with Node this requires bundling and adds 2MB to the script size
- bundling is required because of poor performance with node_modules

#### Related information

Provide any related information

- Typescript
- Node.js

Source

function.json:

```json

{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in",
"authLevel": "anonymous",
"route": "api/http-to-table/{table}/{partition}/{row}"
},
{
"name": "res",
"type": "http",
"direction": "out"
},
{
"name": "inOutputTable",
"type": "table",
"direction": "in",
"tableName": "{table}",
"partitionKey": "{partition}",
"rowKey": "{row}",
"connection": "AZURE_STORAGE_CONNECTION_STRING"
},
{
"name": "outOutputTable",
"type": "table",
"direction": "out",
"tableName": "{table}",
"partitionKey": "{partition}",
"rowKey": "{row}",
"connection": "AZURE_STORAGE_CONNECTION_STRING"
}
],
"disabled": false
}

```

This is an attempt to mimic what was reported to work in C# at:

https://stackoverflow.com/a/44900064/567524

```typescript

if (context.bindings.inOutputTable) {
context.bindings.outOutputTable = context.bindings.inOutputTable;
for (let k in data) {
context.bindings.outOutputTable[k] = data[k];
}
} else {
context.bindings.outOutputTable = data;
}

```

Contributor guide

Open the contributing guide

Research direction

Use the supplied function.json reproduction with Azure Table input and output bindings as the starting point. Inspect how table output bindings handle an existing entity, then verify the requested InsertOrMerge behavior: update matching PartitionKey and RowKey values while inserting when no row exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, node.js, typescript
Domain
backend, cloud, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.