Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos DB "PartitionKey has fewer components than defined the collection resource." error in Azure App Service #179

Closed
karamem0 opened this issue Jun 6, 2022 · 1 comment

Comments

@karamem0
Copy link
Contributor

karamem0 commented Jun 6, 2022

Summary

The GetColl operation fails with HTTP 500 status code when running code at Azure App Service. (Local debbuging is succeeded.)
Similar issue is: Azure/azure-cosmos-dotnet-v3#2030

Error message

System.ArgumentException: PartitionKey has fewer components than defined the collection resource.
   at Microsoft.Azure.Documents.Routing.PartitionKeyInternal.GetEffectivePartitionKeyString(PartitionKeyDefinition partitionKeyDefinition, Boolean strict)
   at Microsoft.Azure.Cosmos.Query.Core.ExecutionContext.CosmosQueryExecutionContextFactory.TryCreateCoreContextAsync(DocumentContainer documentContainer, CosmosQueryContext cosmosQueryContext, InputParameters inputParameters, ITrace trace, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Query.Core.AsyncLazy`1.GetValueAsync(ITrace trace, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Query.Core.Pipeline.LazyQueryPipelineStage.MoveNextAsync(ITrace trace)
   at Microsoft.Azure.Cosmos.Query.Core.Pipeline.NameCacheStaleRetryQueryPipelineStage.MoveNextAsync(ITrace trace)
   at Microsoft.Azure.Cosmos.Query.Core.Pipeline.CatchAllQueryPipelineStage.MoveNextAsync(ITrace trace)
   at Microsoft.Azure.Cosmos.Query.QueryIterator.ReadNextAsync(ITrace trace, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.FeedIteratorCore`1.ReadNextAsync(ITrace trace, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync[TResult](ITrace trace, Func`2 task)
   at Microsoft.Azure.Cosmos.ClientContextCore.OperationHelperWithRootTraceAsync[TResult](String operationName, RequestOptions requestOptions, Func`2 task, TraceComponent traceComponent, TraceLevel traceLevel)
   at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.GetEnumerator()+MoveNext()
   at Beef.Data.Cosmos.CosmosDbQuery`2.<>c__DisplayClass15_0`1.<SelectQuery>b__0(IQueryable`1 query)
   at Beef.Data.Cosmos.CosmosDbQuery`2.ExecuteQueryInternal(Action`1 execute)
   at Beef.Data.Cosmos.CosmosDbQuery`2.<>c__DisplayClass5_0.<ExecuteQuery>b__0()
   at Beef.Data.Cosmos.CosmosDbInvoker.WrapInvoke[TResult](Object caller, Func`1 func, CosmosDbBase param, String memberName, String filePath, Int32 lineNumber)
   at Beef.InvokerBase`1.Invoke[TResult](Object caller, Func`1 func, TParam param, String memberName, String filePath, Int32 lineNumber)
   at Beef.Data.Cosmos.CosmosDbQuery`2.ExecuteQuery(Action`1 execute)
   at Beef.Data.Cosmos.CosmosDbQuery`2.SelectQuery[TColl](TColl coll)
   at Beef.Data.Cosmos.CosmosDbQuery`2.SelectQuery[TColl]()
   at Foo.Bar.Business.Data.PersonData.<>c__DisplayClass10_0.<<GetByArgsAsync>b__0>d.MoveNext() in C:\Users\takashi.a.shinohara\Downloads\Foo.Bar\Foo.Bar.Business\Data\Generated\PersonData.cs:line 99
--- End of stack trace from previous location ---
   at Beef.Business.BusinessInvokerBase.WrapInvokeAsync[TResult](Object caller, Func`1 func, BusinessInvokerArgs param, String memberName, String filePath, Int32 lineNumber)
   at Foo.Bar.Business.DataSvc.PersonDataSvc.<>c__DisplayClass9_0.<<GetByArgsAsync>b__0>d.MoveNext() in C:\Users\takashi.a.shinohara\Downloads\Foo.Bar\Foo.Bar.Business\DataSvc\Generated\PersonDataSvc.cs:line 101
--- End of stack trace from previous location ---
   at Beef.Business.BusinessInvokerBase.WrapInvokeAsync[TResult](Object caller, Func`1 func, BusinessInvokerArgs param, String memberName, String filePath, Int32 lineNumber)
   at Foo.Bar.Business.PersonManager.<>c__DisplayClass8_0.<<GetByArgsAsync>b__0>d.MoveNext() in C:\Users\takashi.a.shinohara\Downloads\Foo.Bar\Foo.Bar.Business\Generated\PersonManager.cs:line 105
--- End of stack trace from previous location ---
   at Beef.Business.BusinessInvokerBase.WrapInvokeAsync[TResult](Object caller, Func`1 func, BusinessInvokerArgs param, String memberName, String filePath, Int32 lineNumber)
   at Beef.AspNetCore.WebApi.WebApiGet`3.<>c__DisplayClass3_0.<<ExecuteResultAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Beef.AspNetCore.WebApi.WebApiGet`3.<>c__DisplayClass3_0.<<ExecuteResultAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Beef.InvokerBase`1.WrapInvokeAsync(Object caller, Func`1 func, TParam param, String memberName, String filePath, Int32 lineNumber)
   at Beef.AspNetCore.WebApi.WebApiGet`3.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Beef.AspNetCore.WebApi.WebApiExecutionContextMiddleware.InvokeAsync(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Beef.AspNetCore.WebApi.WebApiExceptionHandlerMiddleware.InvokeAsync(HttpContext context)

Steps to repro

  1. Create Cosmos DB project.
dotnet new beef --company Foo --appname Bar --datasource Cosmos
  1. Run CodeGen.
cd Foo.Bar.CodeGen
dotnet run all
  1. Create Cosmos DB and App Service in Azure.
  2. Deploy code to App Service.

Workaround

Set PertitionKey to null. (not Mac.PartitionKey.None or Mac.PartitionKey.Null)

- var __dataArgs = CosmosDbArgs.Create(_mapper, "Person", Mac.PartitionKey.None, onCreate: _onDataArgsCreate);
+ var __dataArgs = CosmosDbArgs.Create(_mapper, "Person", null, onCreate: _onDataArgsCreate);
@karamem0
Copy link
Contributor Author

It seems to be fixed in the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant