fix: avoid mutating query config#3720
Open
GiHoon1123 wants to merge 3 commits into
Open
Conversation
Fixes brianc#2651. normalizeQueryConfig() wrote values/callback directly onto the object it was given instead of copying it first. Reusing the same config object across calls (callback style, then promise style) left a stale callback on it, so a later promise-style call would see query.callback already set, skip creating the promise, and silently return undefined while the real result went to the old callback instead. Copy the object before writing to it so the caller's config is never touched, and add regression tests for both the direct case and the callback-then-promise reuse scenario.
charmander
reviewed
Jul 27, 2026
| // can take in strings or config objects | ||
| config = typeof config === 'string' ? { text: config } : config | ||
| // Copy config so normalization does not mutate the caller's object. | ||
| config = typeof config === 'string' ? { text: config } : { ...config } |
Collaborator
There was a problem hiding this comment.
This is a potential breaking change for query objects that don’t have own enumerable query config properties. I’d say return an object like { callback: config.callback, values: config.values, config } and have callers access normalizedConfig.config?.otherProperty, but that would be a breaking change for normalizeQueryConfig itself, so… another function?
Author
There was a problem hiding this comment.
Thanks, good catch. I switched this away from object spread so it keeps the original prototype and property descriptors while still avoiding mutation of the caller's object.
I added a unit test with an inherited text getter for this case. Also ran make test-unit, yarn lint, and yarn build.
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.
Fixes #2651
client.query()addscallbackandvaluesto config objects passed by the caller. Reusing the same object can make a later promise-style call returnundefined.Copy the config before normalizing it and add regression tests for config reuse and mutation.