From e312c4478a6b7904683695cb705214837ddb6213 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Tue, 10 Feb 2026 12:31:57 +0100 Subject: [PATCH] direct: simplify old state inference when no local diff exists When there's a remote diff but no local diff for a field, it means oldState == newConfig for that field. We can therefore use ch.New (from newConfig) directly as the old state value, rather than attempting to fetch it from oldState with structaccess.Get. This simplifies the code and removes unnecessary error handling. Co-Authored-By: Claude Sonnet 4.5 --- bundle/direct/bundle_plan.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bundle/direct/bundle_plan.go b/bundle/direct/bundle_plan.go index cd2d8a18ab..fe0a5ab051 100644 --- a/bundle/direct/bundle_plan.go +++ b/bundle/direct/bundle_plan.go @@ -334,15 +334,11 @@ func prepareChanges(ctx context.Context, adapter *dresources.Adapter, localDiff, for _, ch := range remoteDiff { entry := m[ch.Path.String()] if entry == nil { - // we have difference for remoteState but not difference for localState - // from remoteDiff we can find out remote value (ch.Old) and new config value (ch.New) but we don't know oldState value - oldStateVal, err := structaccess.Get(oldState, ch.Path) - var notFound *structaccess.NotFoundError - if err != nil && !errors.As(err, ¬Found) { - log.Debugf(ctx, "Constructing diff: accessing %q on %T: %s", ch.Path, oldState, err) - } + // We have a difference for remoteState but not for localState. + // No local diff means oldState == newConfig for this field, + // so ch.New (from newConfig) is also the oldState value. m[ch.Path.String()] = &deployplan.ChangeDesc{ - Old: oldStateVal, + Old: ch.New, New: ch.New, Remote: ch.Old, }