question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Push-OutputBinding for table storage does not overwrite existing entities

See original GitHub issue

If the rowKey already exists in the table the entity is not overwritten, but an error is raised. This makes Push-OutputBinding a one-trick-pony wrt. table storage and any workaround defeats the purpose of making integration with Azure Table Storage easy and straightforward.

$Entity = @{
    partitionKey = "SOME_PARTITION_KEY"
    rowKey = "key_that_already_exists_in_the_table"
}
Push-OutputBinding -Name outputTable -Value $Entity
# results in an error "The specified entity already exists"

I would suggest adding a -Force parameter that means overwrite existing entries. This should be trivial as instead of using the insert operation you could use the upsert operation.

Not sure if this should then be an insert or replace or a insert or merge. Perhaps something that can be defined in the integration itself, but either will do as a temporary measure.

Or am I missing something since I could find no mention of this issue anywhere?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
spaellingcommented, Aug 6, 2019

@spaelling Thank you, I see what you mean, -Clobber is not supposed to solve this. We’ll need to think how to make this configurable, as the current behavior is also desirable sometimes: either use -Force as you suggested, or come up with another parameter.

Perhaps make it work like Out-File where -NoClobber:

NoClobber prevents an existing file from being overwritten and displays a message that the file already exists. By default, if a file exists in the specified path, Out-File overwrites the file without warning.

In the case of table storage the default behavior could be to overwrite an existing row, but one could work around this using the -NoClobber switch.

But it would probably be best to adopt the two upsert operations already established in table storage

  • Insert or replace If the Insert Or Replace Entity operation is used to replace an entity, any properties from the previous entity will be removed if the new entity does not define them. Properties with a null value will also be removed.
  • Insert or merge If the Insert Or Merge Entity operation is used to merge an entity, any properties from the previous entity will be retained if the request does not define or include them. Properties with a null value will also be retained.

You could implement this by adding an -Upsert parameter (only works with table storage)

$Entity = @{
    partitionKey = "SOME_PARTITION_KEY"
    rowKey = "key_that_already_exists_in_the_table"
}
# replaces the existing row with data from $Entity
Push-OutputBinding -Name outputTable -Value $Entity -Upsert Replace

# merges the data from existing row with data from $Entity
Push-OutputBinding -Name outputTable -Value $Entity -Upsert Merge
0reactions
julian-wendtcommented, Jun 14, 2023

Is there already an update on this topic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell and Azure storage table (INSERT OR REPLACE)
The operation will update an existing entity or inserts a new entity if it does not exist in the table. Regarding how to...
Read more >
Azure Tables output bindings for Azure Functions
Use an Azure Tables output binding to write entities to a table in Azure Cosmos DB for Table or Azure Table Storage.
Read more >
Insert Or Replace Entity (REST API) - Azure Storage
The Insert Or Replace Entity operation replaces an existing entity or inserts a new entity if it does not exist in the table....
Read more >
Updating and Deleting Table Storage Entities with Azure ...
However, the bindings don't directly support updating and deleting entities (yet). But it's actually pretty easy to support updates and deletes.
Read more >
Update Your Azure Functions Table Storage Bindings
This will completely change how you bind to Table storage. You can already build isolated process C# functions today with .NET 6. However,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found