Skip to content

Commit bccc9e5

Browse files
aitools: Fix default_catalog handling in init-template commands (#4312)
## Changes Only set `default_catalog` when explicitly provided via `--catalog` flag. ## Why Generated projects that used the `default` template were getting an empty `catalog:` field instead of using the workspace default. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 10b3513 commit bccc9e5

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

experimental/aitools/cmd/init_template/empty.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
"github.com/databricks/cli/cmd/root"
8-
"github.com/databricks/cli/experimental/aitools/lib/middlewares"
98
"github.com/databricks/cli/libs/template"
109
"github.com/spf13/cobra"
1110
)
@@ -62,16 +61,14 @@ After initialization:
6261
return fmt.Errorf("--language must be 'python', 'sql', or 'other', got '%s'", language)
6362
}
6463

65-
// Default to workspace default catalog if not specified
66-
if catalog == "" {
67-
catalog = middlewares.GetDefaultCatalog(ctx)
68-
}
69-
7064
configMap := map[string]any{
7165
"project_name": name,
7266
"personal_schemas": "yes",
7367
"language_choice": language,
74-
"default_catalog": catalog,
68+
}
69+
70+
if catalog != "" {
71+
configMap["default_catalog"] = catalog
7572
}
7673

7774
return MaterializeTemplate(ctx, TemplateConfig{

experimental/aitools/cmd/init_template/job.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55

66
"github.com/databricks/cli/cmd/root"
7-
"github.com/databricks/cli/experimental/aitools/lib/middlewares"
87
"github.com/databricks/cli/libs/template"
98
"github.com/spf13/cobra"
109
)
@@ -50,19 +49,16 @@ After initialization:
5049
return errors.New("--name is required. Example: init-template job --name my_job")
5150
}
5251

53-
// Default to workspace default catalog if not specified
54-
if catalog == "" {
55-
catalog = middlewares.GetDefaultCatalog(ctx)
56-
}
57-
5852
configMap := map[string]any{
5953
"project_name": name,
6054
"include_job": "yes",
6155
"include_pipeline": "no",
6256
"include_python": "yes",
6357
"serverless": "yes",
6458
"personal_schemas": "yes",
65-
"default_catalog": catalog,
59+
}
60+
if catalog != "" {
61+
configMap["default_catalog"] = catalog
6662
}
6763

6864
return MaterializeTemplate(ctx, TemplateConfig{

experimental/aitools/cmd/init_template/pipeline.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
"github.com/databricks/cli/cmd/root"
8-
"github.com/databricks/cli/experimental/aitools/lib/middlewares"
98
"github.com/databricks/cli/libs/template"
109
"github.com/spf13/cobra"
1110
)
@@ -59,16 +58,14 @@ After initialization:
5958
return fmt.Errorf("--language must be 'python' or 'sql', got '%s'", language)
6059
}
6160

62-
// Default to workspace default catalog if not specified
63-
if catalog == "" {
64-
catalog = middlewares.GetDefaultCatalog(ctx)
65-
}
66-
6761
configMap := map[string]any{
6862
"project_name": name,
6963
"personal_schemas": "yes",
7064
"language": language,
71-
"default_catalog": catalog,
65+
}
66+
67+
if catalog != "" {
68+
configMap["default_catalog"] = catalog
7269
}
7370

7471
return MaterializeTemplate(ctx, TemplateConfig{

0 commit comments

Comments
 (0)