Repository navigation
MOD-17687 Support Auto-Create missing paths - #1640
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1640 +/- ##
==========================================
+ Coverage 85.84% 88.06% +2.21%
==========================================
Files 15 17 +2
Lines 5278 5957 +679
==========================================
+ Hits 4531 5246 +715
+ Misses 747 711 -36 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ting and missing targets together, then prepare detached subtrees before attachment.
good idea, check now |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
There are 4 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3ea575e. Configure here.
| struct PathCalculatorData<'i, S: SelectValue, UPT: UserPathTracker> { | ||
| struct PathCalculatorData<'v, 'i, S: SelectValue, UPT: UserPathTracker> { | ||
| results: Vec<CalculationResult<'i, S, UPT>>, | ||
| visitor: Option<&'v mut dyn FnMut(CalculationResult<'i, S, UPT>)>, |
There was a problem hiding this comment.
Can the callback signature changed to return result ? currently we can not stop traversing ,
I think once we see an error we should stop
| } | ||
|
|
||
| fn create_object(&self, fields: Vec<(String, IValue)>) -> RedisResult<IValue> { | ||
| let mut object = IObject::new(); |
There was a problem hiding this comment.
Can we initialize the object with the known capacity to avoid reallocations for big nested objects?
| // creation list can mean that every target already exists. | ||
| let nx_has_existing_targets = | ||
| op == SetOptions::NotExists && auto_create_enabled() && { | ||
| let targets = calc_once(query.clone(), doc); |
There was a problem hiding this comment.
should we return a ref flag from prepare_set that tells us wether we founf existing target or not ? and avoid this work ?
| redis_key.notify_keyspace_event(ctx, "json.set")?; | ||
| manager.apply_changes(ctx); | ||
| REDIS_OK | ||
| let new_doc = if path == JSON_ROOT_PATH { |
There was a problem hiding this comment.
it seems like this path and merge has shared logic , should we use some helper function ?
| if query.is_projection() { | ||
| return Err(err_projection_readonly()); | ||
| } | ||
| if calc_once(query.clone(), doc).is_empty() && !can_create(query.clone(), doc)? { |
There was a problem hiding this comment.
can we avoid double travrsal ?
There was a problem hiding this comment.
I combined the existing-target and creation checks into one traversal; MSET still re-plans during the write
| query: Query, | ||
| option: SetOptions, | ||
| ) -> RedisResult<Vec<UpdateInfo>> { | ||
| if option == SetOptions::NotExists { |
There was a problem hiding this comment.
Could we reject projections before the NX early return? The caller catches this later, but checking here keeps validation consistent.
|
|
||
| /// Arithmetic shared by OSS writes and creation preflight on every backend. | ||
| /// Integer operations must fit i64; floating-point results must be finite. | ||
| pub(crate) fn number_op_result<V: SelectValue, F1, F2>( |
There was a problem hiding this comment.
Can you add unit tests for this helper, covering integer overflow/underflow, mixed integer and float inputs, non-finite results, and large integers that fall back to f64?
| // keep their replies. MSET handles the depth error explicitly as nil. | ||
| // No target with this suffix can fit. Reject before exposing a | ||
| // target or allocating the remaining creation sites. | ||
| if value_type.is_none() && suffix_len >= MAX_DEPTH { |
There was a problem hiding this comment.
Can we include the parent depth in this check before copying the missing suffix into every target?
I think that a key with 127 nested obj already exceed it
There was a problem hiding this comment.
kept the parent-depth check after pruning because SET may replace an ancestor and discard those over-depth creation targets; rejecting them earlier would fail a valid write.
| let mut resolution = Ok(()); | ||
| // Evaluate the prefix on the original document. Re-evaluating a filter | ||
| // after seeding can lose matches or select unrelated new targets. | ||
| visit_once_with_paths(query, root, |matched| { |
There was a problem hiding this comment.
Maybe we should stop evaluating once resolve match return an error ?
| } | ||
| let suffix = object_suffix(&mut query); | ||
| let mut creatable = false; | ||
| visit_once_with_paths(query, root, |matched| { |
There was a problem hiding this comment.
We only need one creatable target here. Once we find it, can we stop the traversal? The || skips the suffix check, but we still go through all the remaining matches.

Adds opt-in creation of missing object paths (
json-auto-create-deep-paths yes, disabled by default).JSON.SET,JSON.MSET,JSON.MERGE.JSON.ARRAPPEND,JSON.ARRINSERT(index0only),JSON.STRAPPEND,JSON.NUMINCRBY.JSON.SET k $.a.b 5on{}produces{"a":{"b":5}}.Performance results
Why I kept path-based attachment
parent paths again to attach them.
paths, and ~1–2% slowdowns for shallow fan-out. It still required attachment-time traversal.
discovery would introduce invalidation constraints across backends; path-based attachment keeps the preparation boundary and works consistently with current implementors.
Note
High Risk
Changes JSON mutation semantics, replication/AOF behavior when the flag differs across nodes, and adds complex multi-target write planning with partial-attachment edge cases.
Overview
Adds
json-auto-create-deep-paths(load-time, default off) so JSON write commands can materialize missing object keys along a path instead of failing or returning nil. Documented inmodule.conf; registered as an immutable module bool inlib.rs. Array indexes are still never invented.Command behavior when enabled:
JSON.SET/JSON.MERGE/JSON.MSETuse a newauto_createpipeline—resolve prefix matches once, walk trailing object keys, build detached subtrees, thendict_addattach before applying updates or seeds. Missing keys on absent documents can be built viaroot_key_chain/nest_in_objects.JSON.NUMINCRBY,JSON.STRAPPEND,JSON.ARRAPPEND, andJSON.ARRINSERT(index0only) seed new leaves (0,"",[]) through the same preparation path; MULTBY/POWBY and non-zero ARRINSERT keep prior semantics.json_pathsupport:QueryisClonewithpop_last_object_key(single-key suffixes only). Path evaluation gainsvisit_once_with_paths/visit_with_paths_on_rootusingControlFlowso traversal can stop early without collecting all matches—used heavily during path resolution.Supporting changes:
Managergainsclone_value/create_object; sharednumber_op_resultinnumber.rs. Coverage workflow pins Redis via.install/get-redis-ref.sh;make coverageno longer ignores test failures. New benchmarks exercise deep-path SET/MSET with auto-create on.Reviewed by Cursor Bugbot for commit 66348d3. Bugbot is set up for automated code reviews on this repo. Configure here.