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

Feature: Upsert Table Entity: Support Changing Existing Entities

Open ricklove opened this issue 8 years ago • 20 comments
trafficstars

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:


{
 "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


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;
}

ricklove avatar Jul 07 '17 13:07 ricklove

This is a feature we need to add to support upserting. We only currently support insert.

christopheranderson avatar Jul 07 '17 18:07 christopheranderson

Ok, I changed the title to better reflect that.

If you could point me to the correct location, I could write the code and do a pull request.

ricklove avatar Jul 07 '17 19:07 ricklove

Literally just hit this problem, really rather not have to drop back to C# and using the full Azure Storage library, love to see if there was a workaround

benc-uk avatar Jul 14 '17 22:07 benc-uk

I could find no workaround using the binding.

Also, heads up: Blobs also blow up, but in a different situation (if you try to read a blob that doesn't exist):

So we have the following situation:

Tables

  • in (Exists)
  • in (Not Found)
  • out (Create)
  • FAIL out (Modify)

Blobs:

  • in (Exists)
  • FAIL in (Not Found)
  • out (Create)
  • out (Modify)

Also, you can't set Blob Metadata with the binding if you need that.

The Azure Storage SDK works fine and my performance tests show no significant difference between using the bindings and using the Node SDK. However, I have to bundle everything with webpack for it to perform and its not a simple function anymore when you need a build process.

ricklove avatar Jul 16 '17 02:07 ricklove

Thanks. That's a real shame.
If you're not using bindings you're losing 60% of what Functions is all about IMO, plus I really don't want to mess with webpack. I think I'll switch to a regular Web or API App until there's some progress on this with the WebJobSDK.

benc-uk avatar Jul 16 '17 06:07 benc-uk

any news on this? this seems rather essential.

ThomasPe avatar Nov 04 '17 11:11 ThomasPe

I agree with @ThomasPe - this would be an excellent feature.

jamesaarondevlin avatar Jan 18 '18 21:01 jamesaarondevlin

Any news on this

Akayeshmantha avatar Jan 30 '18 17:01 Akayeshmantha

Anything? This is a glaring omission.

michaeldaw avatar Mar 21 '18 21:03 michaeldaw

We currently do not have a plan for when we might address this feature gap. Our current focus is on functions V2 (including webjobs v3) and at this time we are not tracking this gap as a blocker for that release.

paulbatum avatar Mar 21 '18 22:03 paulbatum

With respect, why? It seems as though using bindings to accomplish operations like this is exactly the intention for functions. If you can't even edit the data in tables then it should at least be documented up front (on https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table#output) with instructions on how to achieve it.

unwitting avatar Mar 29 '18 10:03 unwitting

It really makes sense to call the upsert as the basic feature for functions . If not document them properly so that people like us dont end up spending time in rework.

ganeshchippada avatar Mar 29 '18 16:03 ganeshchippada

@unwitting It is simply a matter of prioritization and working with a limited set of resources. We are spending our time on issues that impact reliability, performance, or having the right logs to track down a problem. We are also working on issues that completely block a customer from adopting functions (i.e. issues with no workaround). The feature discussed in this issue does not fall into any of those categories and that is why it is not being worked on.

paulbatum avatar Mar 29 '18 17:03 paulbatum

See here for a docs PR to make this clearer: https://github.com/MicrosoftDocs/azure-docs/pull/6481

paulbatum avatar Mar 29 '18 17:03 paulbatum

Awesome, thanks for the docs update. I didn't realise the azure-docs are OS, that's great.

unwitting avatar Apr 03 '18 09:04 unwitting

Any update on this issue? does it support the upserting now? Thanks

ablehome17 avatar Apr 22 '20 04:04 ablehome17

Man, what a disappointing waste of time. The documentation around node functions + table storage bindings is so bad.

ChuckJonas avatar Sep 08 '21 16:09 ChuckJonas

Any update on this?

lucas4ntonio avatar Dec 30 '21 19:12 lucas4ntonio

Any updates?

ts-62020 avatar Mar 11 '22 11:03 ts-62020

Still not? Come on!

manualbashing avatar May 06 '25 13:05 manualbashing