Azure / azure-cosmos-table-dotnet

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

Creating a table with IndexingMode.None throws an exception #68

Open RyanMarcotte opened 3 years ago

RyanMarcotte commented 3 years ago

SDK v1.0.7

// always throws exception
await cloudTable.CreateIfNotExistsAsync(IndexingMode.None, null, cancellationToken)
Microsoft.Azure.Cosmos.Table.StorageException
Message: {"Errors":["Indexing mode value cannot be 'none' when automatic indexing is specified as 'true'."]}
ActivityId: 44e6d0e3-ea7c-4fd0-acfd-b5b582f35d26, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.9.2, Windows/10.0.19041 documentdb-netcore-sdk/2.10.0
   at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionOperationHelper.ExecuteOperationAsync[TResult](TableOperation operation, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionRetryPolicy.ExecuteUnderRetryPolicy[TResult](Func`1 executionMethod, CancellationToken cancellationToken, OperationContext operationContext, TableRequestOptions requestOptions)
   at Microsoft.Azure.Cosmos.Table.CloudTable.CreateIfNotExistsAsync(TableRequestOptions requestOptions, OperationContext operationContext, String serializedIndexingPolicy, Nullable`1 throughput, CancellationToken cancellationToken)
RyanMarcotte commented 3 years ago

Based on a ReSharper C# dump, in CloudTable.cs

// indexingPolicy.Automatic needs to set to false in this method if mode.HasValue && mode == IndexingMode.None
private static string ToSerializedIndexingPolicy(Microsoft.Azure.Cosmos.IndexingMode? mode)
    {
      IndexingPolicy indexingPolicy = new IndexingPolicy();
      if (mode.HasValue)
        indexingPolicy.IndexingMode = (Microsoft.Azure.Documents.IndexingMode) mode.Value;
      return JsonConvert.SerializeObject((object) indexingPolicy);
    }
PaulCheng commented 3 years ago

This would be a bug in SDK, which we should fix in the future release. The current workaround is to update indexing policy on azure portal under Data Explorer.