Repository navigation
fix(populate): preserve explicit read option inheritance - #16632
AbdelrahmanHafez wants to merge 14 commits into
Conversation
|
Found a couple more potential issues, investigating... |
There was a problem hiding this comment.
🟡 Changes recommended
Deferred nested population with function-valued matches still loses explicit read settings.
1 open issue
What changed in this PR
This PR updates populate read-option inheritance to use the latest explicit query settings, including after cloning, while keeping schema defaults local to each model.
Changes:
- Move read-option inheritance into execution-local populate preparation.
- Remove inheritance that mutates stored populate options.
- Expand regression tests for ordering, null inheritance, nested overrides, schema defaults, and clones.
| File | Description |
|---|---|
test/query.test.js |
Verify read settings passed to populated queries. |
test/model.populate.test.js |
Cover defaults, overrides, null values, nested population, and cloning. |
lib/queryHelpers.js |
Apply explicit read settings to execution-local populate options. |
lib/query.js |
Remove mutation-based inheritance from execution option preparation. |
Review effort: Balanced
vkarpov15
left a comment
There was a problem hiding this comment.
Not liking the shallow clones, however it does look like there's a test failure without them so I'm digging more into why.
| // Inherit explicit query settings, keeping schema defaults local to each model. | ||
| // Use execution-local options so clones can use new read settings. | ||
| for (const key of ['readPreference', 'readConcern']) { | ||
| if (query.options[key] && pop[i].options?.[key] == null) { |
There was a problem hiding this comment.
Here query.options doesn't go through query's optionsForExec(), which the removed code in lib/query.js did - this means that schema-level defaults for readPreference and readConcern aren't getting applied properly if pop[i].options?.[key] == null
| } else { | ||
| pop[i]._queryProjection = projection; | ||
| pop[i]._localModel = query.model; | ||
| pop[i] = { ...pop[i], _queryProjection: projection, _localModel: query.model }; |
There was a problem hiding this comment.
This shallow clone shouldn't be necessary, and may be harmful because it converts PopulateOptions instance into a POJO. However, it does look like tests fail without this shallow clone - worth investigating why.
fix(model+query): handle inherited read preference and read concern on cloned queries
…n cloned queries Re: Automattic#16632

re #15567 #15553
Use the latest explicit read settings for populate, including after cloning:
Keep schema defaults local to each model:
Explicit query options propagate through nested populate. Populate options override them. Null inherits. The same rules apply to
readConcern.This changes schema-default inheritance introduced in d333d8e in 8.17.1. Applications relying on parent defaults reaching other models will change behavior.