Skip to content

Commit c88f570

Browse files
authored
Show warning message if valueFrom is used instead of value_from in app config section (#4429)
## Changes Show warning message if camel case field is used instead of snake case ## Why DABs syntax uses snake case for all the configuration fields. Sometimes users might use camelCase instead which leads to a warning. With this change we guide users to use the correct field name. Fixes #4297 (comment) ## Tests Added an acceptance test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 78852ba commit c88f570

File tree

8 files changed

+58
-4
lines changed

8 files changed

+58
-4
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Added support for UC catalogs (only in direct mode) ([#4342](https://github.com/databricks/cli/pull/4342))
1616
* engine/direct: Fix updates to fields being ignored for database_catalogs, synced_database_tables (([#4388](https://github.com/databricks/cli/pull/4388)))
1717
* engine/direct: Fix migration for database_instances, database_catalog, synced_database_tables ([#4424](https://github.com/databricks/cli/pull/4424))
18+
* Show warning message if valueFrom is used instead of value_from in app config section ([$4429](https://github.com/databricks/cli/pull/4429))
1819

1920
### Dependency updates
2021

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello from the app!")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bundle:
2+
name: test-bundle
3+
4+
resources:
5+
apps:
6+
myapp:
7+
name: myapp
8+
source_code_path: ./app
9+
config:
10+
env:
11+
- name: MY_SECRET
12+
valueFrom: secret://my_secret

acceptance/bundle/apps/value_from_warning/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
>>> [CLI] bundle validate
3+
Warning: Use 'value_from' instead of 'valueFrom'
4+
at resources.apps.myapp.config.env[0]
5+
in databricks.yml:12:13
6+
7+
The field 'valueFrom' should be 'value_from' (snake_case). The 'valueFrom' field will be ignored.
8+
9+
Name: test-bundle
10+
Target: default
11+
Workspace:
12+
User: [USERNAME]
13+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
14+
15+
Found 1 warning
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle validate
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RecordRequests = false
2+
3+
Ignore = [
4+
'.databricks',
5+
]

libs/dyn/convert/normalize.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,27 @@ func (n normalizeOptions) normalizeStruct(typ reflect.Type, src dyn.Value, seen
9898
pk := pair.Key
9999
pv := pair.Value
100100

101-
index, ok := info.Fields[pk.MustString()]
101+
fieldName := pk.MustString()
102+
index, ok := info.Fields[fieldName]
102103
if !ok {
103104
if !pv.IsAnchor() {
105+
// Special case: provide a more helpful message for "valueFrom" vs "value_from"
106+
if fieldName == "valueFrom" {
107+
if _, hasValueFrom := info.Fields["value_from"]; hasValueFrom {
108+
diags = diags.Append(diag.Diagnostic{
109+
Severity: diag.Warning,
110+
Summary: "Use 'value_from' instead of 'valueFrom'",
111+
Detail: "The field 'valueFrom' should be 'value_from' (snake_case). The 'valueFrom' field will be ignored.",
112+
Locations: pk.Locations(),
113+
Paths: []dyn.Path{path},
114+
})
115+
continue
116+
}
117+
}
118+
104119
diags = diags.Append(diag.Diagnostic{
105-
Severity: diag.Warning,
106-
Summary: "unknown field: " + pk.MustString(),
107-
// Show all locations the unknown field is defined at.
120+
Severity: diag.Warning,
121+
Summary: "unknown field: " + fieldName,
108122
Locations: pk.Locations(),
109123
Paths: []dyn.Path{path},
110124
})

0 commit comments

Comments
 (0)