From b0ccdb655f0c8adc96a3ddef5780ae8860a40ea3 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Fri, 21 Jun 2024 10:43:52 +0200 Subject: [PATCH] Set bool pointer to disable lock This cherry-picks from #1490 to address an issue that came up in #1511. The function `dyn.SetByPath` requires intermediate values to be present. If they are not, it returns an error that it cannot index a map. This is not an issue on main where the intermediate maps are always created, even if they are not present in the dynamic configuration tree. As of #1511 we'll no longer populate empty maps for empty structs if they are not explictly set (i.e. a non-nil pointer). We can write a bool pointer to avoid this issue altogether. --- bundle/config/mutator/process_target_mode.go | 15 ++------------- bundle/config/mutator/process_target_mode_test.go | 4 ++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/bundle/config/mutator/process_target_mode.go b/bundle/config/mutator/process_target_mode.go index 53d97a5b40..b50716fd67 100644 --- a/bundle/config/mutator/process_target_mode.go +++ b/bundle/config/mutator/process_target_mode.go @@ -9,7 +9,6 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/libs/auth" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -34,10 +33,8 @@ func (m *processTargetMode) Name() string { func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { if !b.Config.Bundle.Deployment.Lock.IsExplicitlyEnabled() { log.Infof(ctx, "Development mode: disabling deployment lock since bundle.deployment.lock.enabled is not set to true") - err := disableDeploymentLock(b) - if err != nil { - return diag.FromErr(err) - } + disabled := false + b.Config.Bundle.Deployment.Lock.Enabled = &disabled } r := b.Config.Resources @@ -118,14 +115,6 @@ func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) diag.Diagno return nil } -func disableDeploymentLock(b *bundle.Bundle) error { - return b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) { - return dyn.Map(v, "bundle.deployment.lock", func(_ dyn.Path, v dyn.Value) (dyn.Value, error) { - return dyn.Set(v, "enabled", dyn.V(false)) - }) - }) -} - func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics { if path := findNonUserPath(b); path != "" { return diag.Errorf("%s must start with '~/' or contain the current username when using 'mode: development'", path) diff --git a/bundle/config/mutator/process_target_mode_test.go b/bundle/config/mutator/process_target_mode_test.go index 6a38f274fc..03da64e77f 100644 --- a/bundle/config/mutator/process_target_mode_test.go +++ b/bundle/config/mutator/process_target_mode_test.go @@ -330,7 +330,7 @@ func TestDisableLocking(t *testing.T) { ctx := context.Background() b := mockBundle(config.Development) - err := transformDevelopmentMode(ctx, b) + err := bundle.Apply(ctx, b, ProcessTargetMode()) require.Nil(t, err) assert.False(t, b.Config.Bundle.Deployment.Lock.IsEnabled()) } @@ -341,7 +341,7 @@ func TestDisableLockingDisabled(t *testing.T) { explicitlyEnabled := true b.Config.Bundle.Deployment.Lock.Enabled = &explicitlyEnabled - err := transformDevelopmentMode(ctx, b) + err := bundle.Apply(ctx, b, ProcessTargetMode()) require.Nil(t, err) assert.True(t, b.Config.Bundle.Deployment.Lock.IsEnabled(), "Deployment lock should remain enabled in development mode when explicitly enabled") }