Fix insert/upsert creation for nested lists (#15131) #15133
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.
Description
This PR fixes #15131 by allowing the



insert
andupsert
commands to create lists where they may be expected based on the cell path provided. For example, the below would have previously thrown an error, but now creates lists and list elements where necessaryUser-Facing Changes
This change removes errors that were previously raised by
insert_data_at_cell_path
andupsert_data_at_cell_path
. If one of these commands encountered an unknown cell path in cases such as these, it would either raise a "Not a list value" as the list index is used on a record:Or a "Row number too large" when required to create a new list element along the way:

But both now succeed, which seems to be the intention as it is in parity with record behavior. Any consumers depending on this specific behavior will see these errors subside.
This change also includes the public static method
Value::with_data_at_cell_path
that creates a value with a given nested value at a given cell path, creating records or lists based on the path member type. Plugin developers may begin using this method as its part of the public API now, quite similar to related siblingsValue::insert_data_at_cell_path
andValue::upsert_data_at_cell_path
.Tests + Formatting
In addition to unit tests for the altered behavior, both affected user-facing commands (

insert
andupsert
) gained a new command example to both explain and test this change at the user level.Note: A single test did fail locally, due to my config directory differing from expected, but works where this variable is unset (
with-env { XDG_CONFIG_HOME: null } {cargo test}
):After Submitting