Skip to content

Fix empty filter objects failing with an unexpected error - #10532

Merged
glen-84 merged 5 commits into
mainfrom
gai/empty-filter-object-crash
Oct 13, 2026
Merged

glen-84 merged 5 commits into
mainfrom
gai/empty-filter-object-crash

Conversation

@glen-84

@glen-84 glen-84 commented Oct 13, 2026

Copy link
Copy Markdown
Member

Summary

  • A filter object that produces no condition now adds no condition instead of failing with "Unexpected Execution Error". This covers an empty field filter (where: { name: { } }), an empty nested object, an empty some, all, or none element filter, and a spatial distance without a comparison. It matches how an empty top-level where: { } and or: [{ }] already behave, and applies to the queryable provider (in-memory, EF Core, Marten, and Raven), MongoDB, and spatial filtering.
  • When a filter handler skips a field, as it does for a null value it reports as an error, the visitor now pops the operation and type it pushed on entering that field, so the parent field is left through its own handler. On MongoDB, all: null now reports the HC0026 non-null error the queryable provider already reports, instead of "Unexpected Execution Error".
  • Groundwork for Optional<T>.HasValue is true for an input object field set to a variable the request does not provide #10530: once an omitted variable counts as not provided, name: { contains: $search } without $search becomes name: { }.

Test plan

  • New tests cover empty field, nested object, and element filters on the in-memory provider, empty element filters on MongoDB, and distance without a comparison on PostGIS. Each fails with "Unexpected Execution Error" without the fix.
  • The MongoDB all: null snapshots now show the HC0026 error.
  • The filtering, projection, EF Core, PostgreSQL, MongoDB, Marten, Raven, and spatial test suites pass. The projects with new snapshots pass on net8.0, net9.0, net10.0, and net11.0.

Copilot AI lite review requested due to automatic review settings October 13, 2026 09:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified that would block approval.

0 open findings

What changed in this PR

Fixes filter traversal for empty objects and skipped fields so they produce no condition instead of errors across queryable, MongoDB, and spatial providers.

Changes:

  • Avoid enqueueing conditions for empty filters.
  • Correctly clean up operation/type stacks for skipped fields.
  • Add regression tests and update MongoDB error snapshots.
File Description
src/​HotChocolate/​Spatial/​test/​Data.Filters.SqlServer.Tests/​QueryableFilterVisitorDistanceTests.cs Updated as part of this pull request.
src/​HotChocolate/​Spatial/​test/​Data.Filters.SqlServer.Tests/​__snapshots__/​QueryableFilterVisitorDistanceTests.ExecuteAsync_Should_ApplyNoCondition_When_DistanceHasNoComparison.snap Updated as part of this pull request.
src/​HotChocolate/​Spatial/​src/​Data/​Filters/​Expressions/​Handlers/​QueryableSpatialMethodHandler.cs Updated as part of this pull request.
src/​HotChocolate/​MongoDb/​test/​Data.MongoDb.Filters.Tests/​MongoDbFilterVisitorListTests.cs Updated as part of this pull request.
src/​HotChocolate/​MongoDb/​test/​Data.MongoDb.Filters.Tests/​__snapshots__/​MongoDbFilterVisitorListTests.ExecuteAsync_Should_ApplyNoCondition_When_ElementFilterIsEmpty.snap Updated as part of this pull request.
src/​HotChocolate/​MongoDb/​test/​Data.MongoDb.Filters.Tests/​__snapshots__/​MongoDbFilterVisitorListTests.Create_ArrayAnyStringEqual_Expression.snap Updated as part of this pull request.
src/​HotChocolate/​MongoDb/​test/​Data.MongoDb.Filters.Tests/​__snapshots__/​MongoDbFilterVisitorListTests.Create_ArrayAnyObjectStringEqual_Expression.snap Updated as part of this pull request.
src/​HotChocolate/​MongoDb/​src/​Data/​Filters/​Handlers/​List/​MongoDbListOperationHandlerBase.cs Updated as part of this pull request.
src/​HotChocolate/​Data/​test/​Data.Filters.InMemory.Tests/​QueryableFilterVisitorObjectTests.cs Updated as part of this pull request.
src/​HotChocolate/​Data/​test/​Data.Filters.InMemory.Tests/​QueryableFilterVisitorListTests.cs Updated as part of this pull request.
src/​HotChocolate/​Data/​test/​Data.Filters.InMemory.Tests/​__snapshots__/​QueryableFilterVisitorObjectTests.ExecuteAsync_Should_ApplyNoCondition_When_FieldFilterIsEmpty.snap Updated as part of this pull request.
src/​HotChocolate/​Data/​test/​Data.Filters.InMemory.Tests/​__snapshots__/​QueryableFilterVisitorListTests.ExecuteAsync_Should_ApplyNoCondition_When_ElementFilterIsEmpty.snap Updated as part of this pull request.
src/​HotChocolate/​Data/​src/​Data/​Filters/​Visitor/​FilterVisitorBase`2.cs Updated as part of this pull request.
src/​HotChocolate/​Data/​src/​Data/​Filters/​Expressions/​Handlers/​QueryableDefaultFieldHandler.cs Updated as part of this pull request.
src/​HotChocolate/​Data/​src/​Data/​Filters/​Expressions/​Handlers/​List/​QueryableListOperationHandlerBase.cs Updated as part of this pull request.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (19/19)

File Covered Changed Patch %
…/Handlers/List/QueryableListOperationHandlerBase.cs 4 4 100.0% 🟢
…/Filters/Expressions/Handlers/QueryableDefaultFieldHandler.cs 4 4 100.0% 🟢
…/Data/src/Data/Filters/Visitor/FilterVisitorBase`2.cs 6 6 100.0% 🟢
…/Filters/Handlers/List/MongoDbListOperationHandlerBase.cs 1 1 100.0% 🟢
…/Expressions/Handlers/QueryableSpatialMethodHandler.cs 4 4 100.0% 🟢

Project coverage: 58.7% (315541/537943 lines)

@glen-84
glen-84 merged commit 14dc9ab into main Oct 13, 2026
157 checks passed
@glen-84
glen-84 deleted the gai/empty-filter-object-crash branch October 13, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants