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: KeyNotFoundException for queries doing SelectMany on owned collection #34349

Open
maumar opened this issue Aug 3, 2024 · 3 comments
Open

Comments

@maumar
Copy link
Contributor

maumar commented Aug 3, 2024

Query:

public virtual Task Json_collection_SelectMany(bool async)
    => AssertQuery(
        async,
        ss => ss.Set<JsonEntityBasic>()
            .SelectMany(x => x.OwnedCollectionRoot)
            .AsNoTracking(),
        elementSorter: e => (e.Number, e.Name));

exception

Message: 
System.Collections.Generic.KeyNotFoundException : The given key 'o' was not present in the dictionary.

  Stack Trace: 
Dictionary`2.get_Item(TKey key)
CosmosProjectionBindingRemovingExpressionVisitorBase.CreateGetValueExpression(Expression jTokenExpression, IProperty property, Type type) line 628
CosmosProjectionBindingRemovingExpressionVisitorBase.VisitMethodCall(MethodCallExpression methodCallExpression) line 207
ExpressionVisitor.VisitBinary(BinaryExpression node)
CosmosProjectionBindingRemovingExpressionVisitorBase.VisitBinary(BinaryExpression binaryExpression) line 182
ExpressionVisitor.VisitBinary(BinaryExpression node)
CosmosProjectionBindingRemovingExpressionVisitorBase.VisitBinary(BinaryExpression binaryExpression) line 182
ExpressionVisitor.VisitConditional(ConditionalExpression node)
ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)
ExpressionVisitor.VisitBlock(BlockExpression node)
ExpressionVisitor.VisitConditional(ConditionalExpression node)
ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)
ExpressionVisitor.VisitBlock(BlockExpression node)
CosmosProjectionBindingRemovingExpressionVisitorBase.VisitExtension(Expression extensionExpression) line 310
CosmosProjectionBindingRemovingExpressionVisitorBase.VisitExtension(Expression extensionExpression) line 310
CosmosShapedQueryCompilingExpressionVisitor.VisitShapedQuery(ShapedQueryExpression shapedQueryExpression) line 71
ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression) line 96
QueryCompilationContext.CreateQueryExecutorExpression[TResult](Expression query) line 234
QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) line 199
Database.CompileQuery[TResult](Expression query, Boolean async) line 68
QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) line 127
<>c__DisplayClass11_0`1.<ExecuteCore>b__0() line 83
CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) line 66
QueryCompiler.ExecuteCore[TResult](Expression query, Boolean async, CancellationToken cancellationToken) line 79
QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) line 69
EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) line 83
EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken) line 96
ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()

SelectMany should be supported (#34013)

@roji
Copy link
Member

roji commented Aug 5, 2024

Note: we already have OwnedQueryCosmosTest.SelectMany_on_owned_collection which tests exactly this query - except for the AsNoTracking... We also have PrimitiveCollectionsQueryCosmosTest.Column_collection_SelectMany for the scalar (non-entity) version. The projected collection isn't actually owned in that test (otherwise we don't support projecting out owned things in a tracking query).

@roji
Copy link
Member

roji commented Aug 9, 2024

Test: JsonQueryTestBase.Json_collection_SelectMany

@roji roji added this to the 9.0.0 milestone Aug 9, 2024
@roji roji added the type-bug label Aug 9, 2024
@roji
Copy link
Member

roji commented Aug 26, 2024

@ajcvickers I took a brief look, and this looks to me to be a Cosmos shaper issue, related to our switch to VALUE projections - I think the shaper generation erroneously still thinks that the collection of projected owned types is inside an object, but it isn't (any more).

@roji roji assigned ajcvickers and unassigned roji Aug 26, 2024
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
@roji roji modified the milestones: 9.0.0, Backlog Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants