Skip to content

Fix ExpressionHasher constant collision#9765

Open
apereiratl wants to merge 6 commits into
ChilliCream:mainfrom
apereiratl:fix/expression-hasher-constants
Open

Fix ExpressionHasher constant collision#9765
apereiratl wants to merge 6 commits into
ChilliCream:mainfrom
apereiratl:fix/expression-hasher-constants

Conversation

@apereiratl
Copy link
Copy Markdown

VisitConstant was not overridden, so predicates that differ only in their constant values hashed identically, collapsing aliased [UseFiltering] DataLoader branches into one.

  VisitConstant was not overridden, so predicates that differ only in
  their constant values hashed identically — collapsing aliased
  [UseFiltering] DataLoader branches into one.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 22, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Member

@tobias-tengler tobias-tengler left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! :)

Where did you encounter this issue?
Could you add a test in src/HotChocolate/Data/test/Data.Tests/IntegrationTests.cs that shows that the ExpressionHasher fix solves the higher level issue you were having?

Comment thread src/GreenDonut/test/GreenDonut.Data.Tests/Internal/ExpressionHasherTests.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes ExpressionHasher collisions when two predicates differ only by constant values, which previously caused aliased [UseFiltering] DataLoader branches to collapse into one due to identical hashes.

Changes:

  • Adds VisitConstant handling in ExpressionHasher so constant values participate in hashing.
  • Expands unit coverage to ensure predicates with different constants (including captured variables) hash differently.
  • Updates an existing buffer-resize test to account for the new constant hashing payload size.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/GreenDonut/src/GreenDonut.Data/Internal/ExpressionHasher.cs Adds constant-expression hashing and value serialization logic to avoid constant-based hash collisions.
src/GreenDonut/test/GreenDonut.Data.Tests/Internal/ExpressionHasherTests.cs Updates existing hash expectation and adds regression tests for constant/captured-variable hashing; adjusts buffer resize test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/GreenDonut/src/GreenDonut.Data/Internal/ExpressionHasher.cs
Comment thread src/GreenDonut/src/GreenDonut.Data/Internal/ExpressionHasher.cs
Comment thread src/GreenDonut/test/GreenDonut.Data.Tests/Internal/ExpressionHasherTests.cs Outdated
…tionTests.cs, with a small BooksByAuthorPagedDataLoader and an [ExtendObjectType<Author>]. It runs two aliased

  [UseFiltering] calls against a StatefulBatchDataLoader<int, Page<Book>>, differing only in the title eq "..." constant. Pre-fix both aliases collapsed onto one branch; post-fix the snapshot
  has them returning their respective single matches.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/GreenDonut/src/GreenDonut.Data/Internal/ExpressionHasher.cs Outdated
Comment thread src/GreenDonut/src/GreenDonut.Data/Internal/ExpressionHasher.cs Outdated
Comment thread src/GreenDonut/test/GreenDonut.Data.Tests/Internal/ExpressionHasherTests.cs Outdated
@apereiratl apereiratl requested a review from tobias-tengler May 26, 2026 06:41
@apereiratl
Copy link
Copy Markdown
Author

Hi @tobias-tengler I've fixed all the review comments. Please re-review and let me know if there's anything else. Thank you.

@tobias-tengler tobias-tengler requested review from michaelstaib and removed request for tobias-tengler May 26, 2026 08:33
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.

4 participants