Repository navigation
Fix config-remote-sync failing to add a key the YAML already declares - #7947
ilyakuz-db wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Automated review at 58662c4. Each finding was verified against the code.
Not ready yet: 1 blocking issue(s), tagged [blocking]; 1 open question(s) about a change users could be hurt by.
This PR stops bundle config-remote-sync --save from failing with already exists when a mutator has cleared a field the YAML still declares. It does this by resolving those changes against the pre-resolved config as replaces, sending non-sequence edits to the block that wins the merge, and making the patcher replace an existing key on add. The main case works, but the anchor check in ResolveChanges misses anchors defined inside resources, which can abort a save that works at base. The new acceptance output also shows the saved edit never takes effect on the cluster_id target, which needs a decision before merge.
Questions
- [blocking] On a
cluster_idtarget,OverrideComputeclearsjob_cluster_keyon every deploy. So the value--savewrites into the top-level block never reaches the synced target, and the next sync reports the samereplaceagain (cluster_override_existing_key/output.txt, second sync). Should these changes be markedskipand counted, like the variable-reference case atresolve.go:287-292? Or do users really want the top-level value, which other targets deploy, rewritten on every run? - The new branch in
routeChange(sequences.go:369-373) applies only to paths with no sequence. It sends every non-removal edit towinningBlock, with no top-level-first fallback. It isn't involved in thejob_cluster_keyfix, which goes through sequence routing. It fixes a separate case where a top-level value was rewritten while a target override kept winning (split/top_level_field_both_blocks). Should this go in its own PR, per the one-change-per-PR rule, or stay here? (non-blocking)
Comments outside the changed lines
- [nice to have]
cmd/bundle/config_remote_sync.go: This changes whatbundle config-remote-sync --savedoes for users. A save that used to fail now succeeds, these changes are now reported asreplaceinstead ofadd, and a target override's value is now the one rewritten. The diff adds nothing under.nextchanges/. Can you add a fragment under.nextchanges/bundles/?
| if blocks != nil && resolved.leaf.Location().File == "" && configChange.Operation != OperationRemove && | ||
| !slices.ContainsFunc(resolved.steps, func(s sequenceStep) bool { return s.newElement }) { | ||
| if declared, ok := preResolvedValueAt(preResolved, mergedIndexPath.String()); ok { | ||
| if _, inBlock := blocks.winningBlock(declared); inBlock { |
There was a problem hiding this comment.
[blocking] The yamlloader gives values pulled in through <<: *anchor the anchor's own locations. So when the anchor sits inside resources, winningBlock(declared) still maps it to the top-level block, and the comment's anchor exclusion doesn't apply. Example: task A is - &base {task_key: a, job_cluster_key: shared, ...}, task B is - <<: *base with task_key: b, and the target sets cluster_id. B's job_cluster_key becomes a replace at B's path, which has no such key in the file. The replace then fails in applyChange and the whole save aborts. At base the same input stayed an add and wrote the key explicitly on B. Could this check that the routed block actually has the key at the block-local path, or leave the add to the patcher's yamlKeyExists upgrade?
| }}) | ||
| case OperationAdd: | ||
| opType := yamlpatch.OperationAdd | ||
| // A key the file writes as null is absent from the merged config, so the change |
There was a problem hiding this comment.
[nit] The comment says this is for a key the file writes as null, but yamlKeyExists turns an add on any existing mapping key into a replace. The scalar case in TestApplyChangeAddToExistingKey shows job_cluster_key: old being overwritten. For an unrouted change it also means the top-level candidate wins and AltWritePath is never tried. Maybe: "The merged config can lack a key the file declares (written as null, or cleared by a mutator), so the change arrives as an add; as in RFC 6902, an add on an existing key replaces it."
|
Commit: Regression test reportSelected 5 changed tests (limit=20, 0 not selected) 10 tests: regression=8 unreleased=0 coverage=2 failing=0
TestAccept/bundle/config-remote-sync/cluster_override_existing_key/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/config-remote-sync/cluster_override_existing_key/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/config-remote-sync/split/anchored_override_field/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/config-remote-sync/split/anchored_override_field/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/config-remote-sync/split/cleared_key_override/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/config-remote-sync/split/cleared_key_override/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): TestAccept/bundle/config-remote-sync/split/top_level_field_both_blocks/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/config-remote-sync/split/top_level_field_both_blocks/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) |
✅ Integration test reportCommit: 7e0980b
Top 6 slowest tests (at least 2 minutes):
|
andrewnester
left a comment
There was a problem hiding this comment.
Saving now fails when a cluster override clears a merge-inherited key, with the anchor inside or outside resources. Could it add the key as main does, and test both?
| // A key the file writes as null is absent from the merged config, so the change | ||
| // arrives as an add; it replaces the existing key, as in RFC 6902. | ||
| if yamlKeyExists(content, fieldPathCandidate) { | ||
| opType = yamlpatch.OperationReplace |
There was a problem hiding this comment.
Replacing an anchored null or cleared key drops the anchor its aliases need, so the saved file no longer loads. Could replaces skip anchored nodes, as addThroughNullAncestor does?
Co-authored-by: Isaac <no-reply@databricks.com>
…mplex variable references Co-authored-by: Isaac <no-reply@databricks.com>
…ed safely Co-authored-by: Isaac <no-reply@databricks.com>
Changes
bundle config-remote-sync --saveno longer fails withkey ... already exists and can not be addedwhen the remote has a value for a field that the merged configuration lacks but the YAML still declares.OverrideComputedroppingjob_cluster_keyon a target withcluster_id), the change is resolved against the pre-resolved configuration: it is reported asreplace, written to the block whose definition wins the merge, and keeps${...}references.Why
Sync picks add or replace from the merged configuration, which can lack a key the file has, and the YAML patcher rejects an add on an existing key, so the whole save failed.
Tests
Reproduced the error with a
cluster_idtarget first, then added unit tests for the patcher (including anchored keys) and acceptance tests for acluster_idtarget (including${var...}and complex variable values), merge keys with anchors inside and outsideresources, a task split across the top-level and target blocks, and a field declared in both blocks, plain and anchored. Existing config-remote-sync acceptance tests pass unchanged.7e0980b(latest)replace1217292RIGHT-SIZED: the fix lands where changes are located against the pre-mutator YAML7e0980b(latest)7e0980b(latest)7e0980b(latest)58662c4; both points fixed7e0980b(latest)✅ success · ⏳ pending ·⚠️ warning · ❌ failed · ➖ n/a
This pull request and its description were written by Isaac.