fix(repository): dedupe/filter source ids before querying in hasManyThrough inclusion resolver - #11784
Open
karthikchundi-commits wants to merge 1 commit into
Conversation
…hrough inclusion resolver
hasManyThrough's inclusion resolver passed its raw, unfiltered
sourceIds array by reference straight into findByForeignKeys(),
which wraps it in an {inq: [...]} where clause and hands that same
array to the connector without cloning it first. A connector/query
layer that sanitizes an inq array in place (e.g. stripping falsy
values before running the query, as the in-memory connector does)
then mutates that exact array out from under the caller - shrinking
the very sourceIds array the resolver still needed, unmodified, to
correctly zip through-results back onto each original entity via
flattenTargetsOfOneToManyRelation(). That silently misaligns or
truncates the returned array whenever any source entity's key was
undefined (e.g. excluded by a fields filter) or duplicated another
entity's.
hasMany and hasOne inclusion resolvers already had this fixed
(deduplicate(sourceIds).filter(e => e) before querying); hasManyThrough
had no dedup/filter attempt at all - not even a partial one, unlike
hasMany/hasOne before their own fix.
Added a regression test to has-many-through-inclusion-resolver.acceptance.ts
mirroring the existing hasMany/hasOne regression tests: a duplicate
source entity plus one with an undefined key, confirming the result
stays length-3 and aligned with the input. Verified the test actually
catches the bug by temporarily reverting the source fix and
re-running - reproduces the exact truncation (length 2 instead of 3)
this fix addresses. `npx mocha dist/__tests__/**/*.js` in
repository-tests: 126 passing, 8 pending (pre-existing, unrelated),
no failures. eslint and prettier clean on both changed files.
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Karth <karthik.chundi@gmail.com>
4 tasks
dhmlau
approved these changes
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hasManyThrough's inclusion resolver passes its raw, unfilteredsourceIdsarray by reference straight intofindByForeignKeys(), which wraps it in an{inq: [...]}where clause and hands that same array to the connector without cloning it first. A connector/query layer that sanitizes aninqarray in place (e.g. stripping falsy values before running the query, as the in-memory connector does) then mutates that exact array out from under the caller — shrinking the verysourceIdsarray the resolver still needs below, unmodified, to correctly zip through-results back onto each original entity viaflattenTargetsOfOneToManyRelation(). That silently misaligns or truncates the returned array whenever any source entity's key was undefined (e.g. excluded by a fields filter) or duplicated another entity's.hasManyandhasOneinclusion resolvers already had this exact bug fixed (deduplicate(sourceIds).filter(e => e)before querying, same aliasing hazard, same root cause).hasManyThroughhad no dedup/filter attempt at all — not even a partial one, unlikehasMany/hasOnebefore their own fix.Found via a source-reading sweep of the other relation-inclusion resolvers (
belongsTo,referencesMany) after noticing the pattern already fixed forhasMany/hasOne—belongsToandreferencesManywere independently reconfirmed clean (both already pass a genuinely fresh, deduplicated array, never the original reference).Checklist
npm testpasses on your machinehas-many-through-inclusion-resolver.acceptance.tsmirroring the existinghasMany/hasOneregression tests: a duplicate source entity plus one with an undefined key, confirming the result stays length-3 and aligned with the input. Verified the test actually catches the bug by temporarily reverting the source fix and re-running — reproduces the exact truncation (length 2 instead of 3) this fix addresses.Testing
126 passing, 8 pending (pre-existing, unrelated to this change), no failures.