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

Getting exception BadRequestException: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception. #9

Closed
jbliss1234 opened this issue Apr 21, 2017 · 8 comments

Comments

@jbliss1234
Copy link

I followed steps in the Readme, and when attempting to register a new user, I get this exception: BadRequestException: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception.

Full Exception race is here:
Microsoft.Azure.Documents.Routing.PartitionRoutingHelper.GetProvidedPartitionKeyRanges(SqlQuerySpec querySpec, bool enableCrossPartitionQuery, bool parallelizeCrossPartitionQuery, PartitionKeyDefinition partitionKeyDefinition, QueryPartitionProvider queryPartitionProvider, string clientApiVersion, out QueryInfo queryInfo) Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext+<TryGetTargetPartitionKeyRangeAsync>d__5.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext+<ExecuteOnceAsync>d__4.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.BackoffRetryUtility+<>c__DisplayClass1_0+<<ExecuteAsync>b__0>d.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.BackoffRetryUtility+<ExecuteRetry>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.Azure.Documents.BackoffRetryUtility+<ExecuteRetry>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.BackoffRetryUtility+<ExecuteAsync>d__1.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase+<ExecuteWithRetryPolicy>d__46.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DefaultDocumentQueryExecutionContext+<ExecuteInternalAsync>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.Azure.Documents.Query.DocumentQueryExecutionContextBase+<ExecuteNextAsync>d__35.MoveNext()

@codekoenig
Copy link
Owner

codekoenig commented Apr 21, 2017

It seems you are using DocumentDb automatic partitioning which is unfortunately not yet supported with this provider (see #1) as I did not find a solution yet on how to do support this in an as generic as possible way. There needs to be a possibility to tell this provider how you want to have your data partitioned, and I don't want to force the user of this provider into any partitioning strategy defined by me (i.e. by e-mail TLD or something, that might not be the best solution for everyone).

Currently you have two options when you want to use this provider:

  • For users and roles, add an additional, not auto-partitioned collection to your DocumentDb. Depending on the load you expect on this collection, it might not be an option.
  • Fork this project and add the required code to support partitioning for your specific scenario. If you don't have to support a generic solution, it's pretty easy to implement (you know, pass the partition key on queries and so forth). If you need help on where to add the required bits, let me know.

Else, you'd have to wait until I come up with a generic solution that lets you configure this provider on how it should partition your data.

@TheDarkCode
Copy link
Contributor

I'm going to try to put up my fork of this which addresses the partitioning issue within the next week or so. But you'll have lots of breaking changes since I changed all the naming conventions of classes and other properties to be more generic for Identity.

For now, you can just add the following parameter to each document query and recompile this project:
new FeedOptions { EnableCrossPartitionQuery = true }

@codekoenig
Copy link
Owner

As discussed, this behavior is as designed. Please track #1 to see progress on implementing support for partitioning.

@greg-dickie
Copy link

Sorry to bring up an old issue, but I'm working with your library and would like to add my own support for partitioning. I think I have it mostly working except when the FindByIdAsync method is called on the user store. I have my partition for users as the domain name of the email address and I can't think of a way to figure out what that would be based on the user id.

It also appears to me that you can't enable cross partition queries for RequestOptions so I have to supply the correct partition key.

Any thoughts on how I can solve this? I apologize if I'm going about this the wrong way, I'm new to Github and Cosmos DB and I'm learning as I go.

Thanks for any help you can give,
Greg

@codekoenig
Copy link
Owner

codekoenig commented Feb 4, 2018

@greg-dickie Yea, that's a huge problem. I'm thinking about how to tackle support for partitioning for a while now - see #1 - but it's very tricky because of how ASP.NET Identity works and you can end up with just knowing about the User ID and nothing else.

So actually you would have to have some information within the UserId that tells you which partition to use. Or you could use some lookup store where you cache/hold a mapping from UserId to it's partition (maybe in another DocumentDb Collection, in a Redis Cache, ...) - all of this would of course require a custom implementation.

What this all comes down to would be a custom implementation of ASP.NET Identity if one would want to generalize partitioning support -and that's pretty much out of scope :). Personally, I moved on from using ASP.NET Identity with Documentdb when auto partitioning is required - for an application I'm currently developing I store the users in Azure AD B2C only (instead of storing them in DocumentDb and using IdentityServer based on that user store).

@greg-dickie
Copy link

greg-dickie commented Feb 5, 2018 via email

@Jeremywhiteley
Copy link

Jeremywhiteley commented Feb 5, 2018

I found this guide on how to set up Cosmos DB with Azure Ad B2C using a function app. I am surprised Microsoft hasn't given us more "how to examples" with this scenario. With 5g coming out, this is going to be big for cosmos DB.

https://github.com/adamhockemeyer/Azure-Functions---CosmosDB-ResourceToken-Broker

Wiki is here: https://github.com/adamhockemeyer/Azure-Functions---CosmosDB-ResourceToken-Broker/wiki

@scottkuhl
Copy link

For users and roles, add an additional, not auto-partitioned collection to your DocumentDb.

@codekoenig How exactly do you do that in Cosmos DB?

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

6 participants