-
Notifications
You must be signed in to change notification settings - Fork 43
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
Comments
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:
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. |
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: |
As discussed, this behavior is as designed. Please track #1 to see progress on implementing support for partitioning. |
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-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). |
Thanks Bernhard, I think I’ve been able to work around the issue enough for my situation by calling different methods.
Azure AD B2C definitely looks interesting though, I’ll take a look at that as well.
Thanks again,
Greg
From: Bernhard Koenig<mailto:[email protected]>
Sent: Sunday, February 4, 2018 11:52 AM
To: codekoenig/AspNetCore.Identity.DocumentDb<mailto:[email protected]>
Cc: greg-dickie<mailto:[email protected]>; Mention<mailto:[email protected]>
Subject: Re: [codekoenig/AspNetCore.Identity.DocumentDb] 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 q...
@greg-dickie<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgreg-dickie&data=02%7C01%7C%7Cbb6865ade6cb475ac78908d56c0070c9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636533671498457930&sdata=fu%2F0c7nm2l19VK%2Blz4%2BkpuR31zpMhq%2FIY5GMGUTEPTo%3D&reserved=0> Yea, that's a huge problem. I'm thinking about how to tackle support for partitioning for a while now - see #1<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcodekoenig%2FAspNetCore.Identity.DocumentDb%2Fissues%2F1&data=02%7C01%7C%7Cbb6865ade6cb475ac78908d56c0070c9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636533671498457930&sdata=YhO%2BH2dFOHXYjWSi2s2A6%2BN6Iy%2FN8FU1oe%2Fz4wF42qY%3D&reserved=0> - 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 - what would 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).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcodekoenig%2FAspNetCore.Identity.DocumentDb%2Fissues%2F9%23issuecomment-362930003&data=02%7C01%7C%7Cbb6865ade6cb475ac78908d56c0070c9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636533671498457930&sdata=OUBTv8d4pjyjIjEYhAv1mMVl4rKUGSejoO1IWWji4hQ%3D&reserved=0>, or mute the thread<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAdR9x7A3w7q4Xiux7j54mafI9dosjt6Jks5tRfxrgaJpZM4ND0A9&data=02%7C01%7C%7Cbb6865ade6cb475ac78908d56c0070c9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636533671498614177&sdata=BQ5FgyU8Ld3jvaeW1zzs6GUCo3gshifH7hzPwab1HmI%3D&reserved=0>.
|
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 |
For users and roles, add an additional, not auto-partitioned collection to your DocumentDb. @codekoenig How exactly do you do that in Cosmos DB? |
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()
The text was updated successfully, but these errors were encountered: