Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/air/convert-to-dabs-existing-root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Reject an existing bundle configuration under any supported filename when running `databricks air convert-to-dabs` without `--force`. ([#7853](https://github.com/databricks/cli/pull/7853))
12 changes: 8 additions & 4 deletions cmd/air/convert_to_dabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,14 @@ func writeBundle(ctx context.Context, cfg *runConfig, configPath, dir string, fo
return os.WriteFile(target, data, 0o600)
}

bundlePath := filepath.Join(dir, "databricks.yml")
const bundleFileName = "databricks.yml"
bundlePath := filepath.Join(dir, bundleFileName)
if !force {
if _, err := os.Stat(bundlePath); err == nil {
return nil, fmt.Errorf("databricks.yml already exists in %s; pass --force to overwrite or remove it", dir)
if name := bundleFileIn(dir); name != "" {
if name == bundleFileName {
return nil, fmt.Errorf("%s already exists in %s; pass --force to overwrite or remove it", name, dir)
}
return nil, fmt.Errorf("%s already exists in %s; move or remove it before converting", name, dir)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] This error correctly avoids suggesting --force, but nothing stops a user from passing it anyway. When databricks.yaml (or bundle.yml/bundle.yaml) already exists and force=true, the if !force guard at line 636 is skipped entirely, SaveAsYAML writes databricks.yml alongside it (line 646), and the bundle loader rejects the directory with "multiple bundle root configuration files found" (bundle/config/filename.go:27). TestConvertToDabsForceOverwrite only plants databricks.yml, so this combination is untested. Can you add a check before the SaveAsYAML call that fires even under --force when a different root file is present, and add a test case for it?

}
}
// SaveAsYAML's force arg is passed true unconditionally: the collision check
Expand All @@ -645,7 +649,7 @@ func writeBundle(ctx context.Context, cfg *runConfig, configPath, dir string, fo
if err := quoteJobKey(bundlePath, bundleResourceKey(cfg.ExperimentName)); err != nil {
return nil, err
}
written := []string{"databricks.yml"}
written := []string{bundleFileName}

// Launch artifacts (command.sh + sidecars) under generated_artifacts/.
for _, item := range artifacts {
Expand Down
28 changes: 28 additions & 0 deletions cmd/air/convert_to_dabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ func TestConvertToDabsForceOverwrite(t *testing.T) {
assert.Contains(t, string(regenerated), "ai_runtime_task")
}

func TestConvertToDabsExistingBundleRoot(t *testing.T) {
for _, name := range config.FileNames {
t.Run(name, func(t *testing.T) {
path := writeConfigFile(t, "run.yaml", minimalConfig+"code_source:\n root_path: ./src\n")
dir := filepath.Dir(path)
require.NoError(t, os.Mkdir(filepath.Join(dir, "src"), 0o700))
loaded, err := loadRunConfig(path)
require.NoError(t, err)
existing := filepath.Join(dir, name)
edited := []byte("# hand-edited\n")
require.NoError(t, os.WriteFile(existing, edited, 0o600))

_, err = writeBundle(t.Context(), loaded, path, dir, false)
want := fmt.Sprintf("%s already exists in %s; move or remove it before converting", name, dir)
if name == "databricks.yml" {
want = fmt.Sprintf("databricks.yml already exists in %s; pass --force to overwrite or remove it", dir)
}
require.EqualError(t, err, want)
found, err := config.FileNames.FindInPath(dir)
require.NoError(t, err)
assert.Equal(t, existing, found)
kept, err := os.ReadFile(existing)
require.NoError(t, err)
assert.Equal(t, edited, kept)
})
}
}

// command.sh is the user's command copied verbatim — convert injects no cd. The
// launcher exports $CODE_SOURCE_PATH and runs the command in the launch dir without
// cd-ing, so (as under air run) the command owns its own cd; convert must not add one,
Expand Down
Loading