Cosmos: bad exception for queries with aggregate selecting non-mapped type

Open
#20,677 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
database

Research direction

Start with SelectExpression.GetMappedProjection and CosmosQueryableMethodTranslatingExpressionVisitor.TranslateAverage, using the failing query and stack trace as the entry point. Review NorthwindAggregateOperatorsQueryTestBase.Average_with_unmapped_property_access_throws_meaningful_exception. Done means the unmapped aggregate query reports a meaningful exception instead of KeyNotFoundException.

Written by the indexing model from the issue text.

Description

area-cosmos area-query

query:

ctx.Orders.Average(o => o.ShipVia)

exception:

System.Collections.Generic.KeyNotFoundException : The given key 'EmptyProjectionMember' was not present in the dictionary.
  Stack Trace: 
    Dictionary`2.get_Item(TKey key)
    SelectExpression.GetMappedProjection(ProjectionMember projectionMember) line 131
    CosmosQueryableMethodTranslatingExpressionVisitor.TranslateAverage(ShapedQueryExpression source, LambdaExpression selector, Type resultType) line 193
    QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) line 119
    MethodCallExpression.Accept(ExpressionVisitor visitor)
    ExpressionVisitor.Visit(Expression node)
    QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) line 91
    Database.CompileQuery[TResult](Expression query, Boolean async) line 71
    QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) line 112
    <>c__DisplayClass9_0`1.<Execute>b__0() line 96
    CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler) line 76
    CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) line 51
    QueryCompiler.Execute[TResult](Expression query) line 92
    EntityQueryProvider.Execute[TResult](Expression expression) line 79
    Queryable.Average[TSource](IQueryable`1 source, Expression`1 selector)
    QueryAsserter`1.AssertAverage[TResult](Func`2 actualQuery, Func`2 expectedQuery, Expression`1 actualSelector, Expression`1 expectedSelector, Action`2 asserter, Boolean async) line 1305
    NorthwindAggregateOperatorsQueryTestBase`1.Average_with_unmapped_property_access_throws_meaningful_exception(Boolean async) line 1896
Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.