fix(sync): do not blank a ResourceTarget id when the lookup misses - #1581
Open
cplieger wants to merge 1 commit into
Open
fix(sync): do not blank a ResourceTarget id when the lookup misses#1581cplieger wants to merge 1 commit into
cplieger wants to merge 1 commit into
Conversation
Managed-mode writeback can emit TOML that Komodo itself cannot parse, which
leaves the sync permanently broken until a human edits the file.
replace_resource_target_ids! rewrote each id to the resource name and fell
back to unwrap_or_default() when the lookup missed, so a miss produced an
empty String. ResourceTarget is adjacently tagged (tag = "type", content =
"id"), and TOML_PRETTY_OPTIONS sets skip_empty_string, so the empty id is
dropped from the emitted table. The result is
resources = [{ type = "Stack" }]
which cannot be deserialized back into a ResourceTarget, so every later read
of that file fails with 'missing field id'.
Leaving the id untouched on a miss keeps the value round-trippable. Nothing
else changes: the only behavioural difference is what happens on a miss, and
the previous outcome on a miss was an unparseable file.
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.
Managed-mode writeback can emit TOML that Komodo itself cannot parse, which leaves the sync permanently broken until someone edits the file by hand. Hit this on a live deployment; the deploy pipeline stopped until I removed the offending line manually.
What happens
A
Commit Syncwrote this into myresources.toml:Every read of the file after that failed:
Why
Three existing behaviours compose into an unparseable file:
replace_resource_target_ids!rewrote each id to the resource name with.map(|r| r.name.clone()).unwrap_or_default(), so a missed lookup yields an emptyString.ResourceTargetis adjacently tagged,#[serde(tag = "type", content = "id")](client/core/rs/src/entities/mod.rs), soidis required to deserialize.TOML_PRETTY_OPTIONSsetsskip_empty_string: true(bin/core/src/sync/toml.rs), so the now-emptyidis omitted from the emitted table.Result:
{ type = "Stack" }, valid TOML syntax but not a validResourceTarget.In my case the lookup missed because the file supplied the target by name, which is how every other synced reference is written, while the cache is keyed by id. Whether names should be accepted there is a separate design question and this PR does not touch it. This change only stops a miss from corrupting the file.
The change
Leave the id untouched when the lookup misses. The only behavioural difference is what happens on a miss, and the previous outcome on a miss was a file that cannot be read back.
Possibly the same class elsewhere
DeploymentImage::Buildis also adjacently tagged and itsbuild_idis blanked the same way inReplaceIds for Deployment, so it looks reachable in principle. I have not reproduced that one and did not want to widen an urgent fix on an untested hypothesis, so I have left it alone. Happy to extend the PR if you would like it covered.The plain
Stringconfig fields nearby (server_id,swarm_id,linked_repo,builder_id) are unaffected, since an empty string there is still parseable.Verification
cargo check -p komodo_coreclean with no new warnings,cargo fmtleaves the change untouched. I have not added a test:bin/corehas no test module today (one#[cfg(test)]in the whole repo, inlib/command) and the macro reads the globalall_resources_cache(), so a unit test would need new scaffolding. Glad to add one if you point me at the shape you would want.