Azure / azure-cosmos-table-dotnet

.NET SDK for Azure Cosmos Table API
14 stars 5 forks source link

`TableName` field does not accept dashes. #46

Closed b0wter closed 4 years ago

b0wter commented 4 years ago

You can use the Azure portal to create tables in an Azure Cosmos DB account that contain dashes, e.g. "my-table-name". However, when I try to use that name in my Azure function project with the Microsoft.Azure.Cosmos.Table library I can no longer run the function because I get the following error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: Validation failed for property 'TableName', value 'my-table-name'. The field TableName must match the regular expression '^[A-Za-z][A-Za-z0-9]{2,62}$'.

Changing the name to "myTableName" makes it work.

** SDK version I am running a .net core 2.1 Azure function project.

** Issue reproduce steps Create an Azure function. Add the Microsoft.Azure.Cosmos.Table nuget package and add an output trigger like this:

public static async Task MyFunction(
            ILogger log,
            [Table("%TableName%", Connection = "ConnectionString")] IAsyncCollector<CacheItem<string>> table)
{
    ...
}

Add the following entry to local.settings.json:

{
    ...
    "TableName": "my-table-name"
    ...
}

Add a table in your Table Storage Account named "my-table-name".

Then run the function. It will fail with the error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunction'. Microsoft.Azure.WebJobs.Host: Validation failed for property 'TableName', value 'my-table-name'. The field TableName must match the regular expression '^[A-Za-z][A-Za-z0-9]{2,62}$'.

** Whether the issue is consistent or sporadic The issue happens each time I start my function.

** Environment Summary Ubuntu 20.04 with the following dotnet packages installed: image

** Any other context, such as stack trace or log.

evo-terren commented 4 years ago

Table names can only be alphanumeric (reference: https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage). I believe they must also not begin with a number. No hyphens allowed.

b0wter commented 4 years ago

Interesting. So the error is either in the documentation or the portal itself? Any idea on where to check that?

evo-terren commented 4 years ago

I'm not really sure what you're asking. The portal doesn't allow hyphens/dashes either:

azure-table-hyphen

I don't see anything that would tell me they are allowed. Are you able to create them with hyphens through the portal?

b0wter commented 4 years ago

I have no idea what I did initially. Sorry for bothering you. Everything is fine the way it is :sweat:

blacree commented 1 year ago

I was able to create a table using hyphen and got the same error when binding the cosmodb table to my function using the table name Error: Validation failed for property 'TableName', value 'crc-cosmodb'. The field TableName must match the regular expression '^[A-Za-z][A-Za-z0-9]{2,62}$'.

blacree commented 1 year ago

I was able to create a table using hyphen and got the same error when binding the cosmodb table to my function using the table name Error: Validation failed for property 'TableName', value 'crc-cosmodb'. The field TableName must match the regular expression '^[A-Za-z][A-Za-z0-9]{2,62}$'.

I didn't get the error when i created a table without hyphen or underscore called "crccosmodb". So apparently you can create table in Azure cosmodb Table using hyphen or underscore without getting any error. Just put in mind that if you plan to use your table with your azure function (python - in my case) create your table without any hyphens or underscores.