Unable to enter insert string into Azure Table storage which contains a space via the Azure CLI, even when quoted
Describe the bug
I'm using the Azure CLI (azure-cli 2.53.0) to insert an entity into an Azure Storage table. The following (ZSH) command works and the entity is inserted.
entity=$(cat <<-END
PartitionKey=${job_number} \
RowKey=available \
author="Aaron+Newton" \
xyz="abc"
END
)
az storage entity insert \
--account-name "$STORAGE_ACCOUNT" \
--table-name "$TABLE_NAME" \
--entity $entity \
--auth-mode login \
--if-exists merge
However, if I remove the + and replace it with a space on the author key-value pair, the command fails:
entity=$(cat <<-END
PartitionKey=${job_number} \
RowKey=available \
author="Aaron Newton" \
xyz="abc"
END
)
az storage entity insert \
--account-name "$STORAGE_ACCOUNT" \
--table-name "$TABLE_NAME" \
--entity $entity \
--auth-mode login \
--if-exists merge
It seems that any space is treated as a delimited for the command itself, even when the string is quoted. When I review the output of the first command, I can see that it stored the literal "Aaron+Newton" against the author property in the table.
There seems to be some workaround using Powershell and the REST API directly (or I can just write a simple program), but has anyone managed to solve this using the Azure CLI?
Related command
az storage entity insert
Errors
The first two lines are some debug from my script.
c7506390696f:~/source/myorg/aaron-infra-sandbox# ./scripts/myapph_seed_event_table.sh
<entity> -> PartitionKey=WPDBUTZ RowKey=available author="Aaron Newton" xyz="abc"
The error is:
dictionary update sequence element #3 has length 1; 2 is required
Issue script & Debug output
Note: you'll need to set the variables STORAGE_ACCOUNT and TABLE_NAME.
entity=$(cat <<-END
PartitionKey=WPDBUTZ \
RowKey=available \
author="Aaron Newton" \
xyz="abc"
END
)
az storage entity insert \
--account-name "$STORAGE_ACCOUNT" \
--table-name "$TABLE_NAME" \
--entity $entity \
--auth-mode login \
--if-exists merge
Expected behavior
A quoted string should be allowed to include spaces, or there needs to be some documentation on how to do this. I would be shocked if "that's unsupported" was the answer here given that this is a common use case.
Environment Summary
azure-cli: 2.53.0
Additional context
The documentation is very sparse on entity examples, so if this is supported, it might be a case of improving the docs. https://learn.microsoft.com/en-us/cli/azure/storage/entity?view=azure-cli-latest
Thank you for opening this issue, we will look into it.
Thank you. For context, we should either be able to insert a quoted string, a base64 encoded string and flag it as base64 encoded, or something like that. But it was very difficult to find examples online. Allowing JSON to be passed in rather than key-value string pairs would be another good option.
It seems to work fine when inputting the values directly instead of using a variable, can you give it a try?
Allowing json is indeed a good suggestion, will look into the implementation.
Okay, that's really strange. This worked on the latest Docker image from https://learn.microsoft.com/en-us/cli/azure/run-azure-cli-docker
3c0e5de661af# az storage entity insert --account-name stmyaccount --table-name job --auth-mode login --if-exists merge --entity PartitionKey=test RowKey=available author="Aaron Newton"
{
"date": "2023-11-02T02:07:59+00:00",
"etag": "W/\"datetime'2023-11-02T02%3A07%3A59.3988124Z'\"",
"version": "2019-02-02"
}
So there must be some obscure error with my script. Thanks for looking into it.