Skip to content

ToPageAsync() (QueryHelpers.EnsureOrderPropsAreSelected) attempts to select Order properties that it should not #8262

@Tommsy64

Description

@Tommsy64

Product

Green Donut

Version

15.1.3

Link to minimal reproduction

https://github.com/Tommsy64/HotChocolate-IssueReproductions/tree/88256b4db5a1a60196bb23e249da85dec8732a66

Steps to reproduce

  1. docker compose up -d to start the ephemeral database (no persistant volume, defaults to port 5433).
  2. dotnet ef database update
  3. dotnet run
  4. Run the following GraphQL query:
query {
  speakers {
    nodes {
      name
    }
  }
}

Exception is thrown:

Property 'System.String Name2' is not defined for type 'HotChocolateIssueReproduction.Types.SpeakerDto' (Parameter 'property')

What is expected?

When OrderBy expressions exist in the Selector, they should not be automatically selected by QueryHelpers.EnsureOrderPropsAreSelected();

What is actually happening?

The following expression contains an OrderBy that causes QueryHelpers.EnsureOrderPropsAreSelected to attempt to select OtherProperty, which does not exist on the Dto.

e => new Dto
        {
            Id = e.Id,
            NotWorking = e.ListOfObjects.OrderByDescending(l => l.OtherProperty).FirstOrDefault()
        });

Relevant log output

message: Property 'System.String Name2' is not defined for type
	'HotChocolateIssueReproduction.Types.SpeakerDto' (Parameter 'property')
  stackTrace: "   at System.Linq.Expressions.Expression.Property(Expression
	expression, PropertyInfo property)\r

	\   at
	GreenDonut.Data.Expressions.QueryHelpers.AddPropertiesVisitorRewriter.V\
	isitMemberInit(MemberInitExpression node)\r

	\   at
	GreenDonut.Data.Expressions.QueryHelpers.AddPropertiesInSelector[T](Exp\
	ression`1 selector, List`1 properties)\r

	\   at
	GreenDonut.Data.Expressions.QueryHelpers.EnsureOrderPropsAreSelected[T]\
	(IQueryable`1 query)\r

	\   at
	GreenDonut.Data.PagingQueryableExtensions.ToPageAsync[T](IQueryable`1
	source, PagingArguments arguments, Boolean includeTotalCount,
	CancellationToken cancellationToken)\r

	\   at
	GreenDonut.Data.PagingQueryableExtensions.ToPageAsync[T](IQueryable`1
	source, PagingArguments arguments, CancellationToken
	cancellationToken)\r

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions