Skip to content

Commit 9df06b4

Browse files
authored
Fixed apps incorrectly using local filesystem path from artifacts path (#4946)
## Changes Fixed apps incorrectly using local filesystem path from artifacts path ## Why Fixes #4924 ## 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 85f0491 commit 9df06b4

7 files changed

Lines changed: 47 additions & 7 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bundle:
2+
name: test-bundle
3+
4+
artifacts:
5+
my_artifact:
6+
type: whl
7+
path: ./src/app
8+
9+
resources:
10+
apps:
11+
my_app:
12+
name: my-app
13+
source_code_path: ./src/app

acceptance/bundle/apps/artifact_and_app_same_path/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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
>>> [CLI] bundle validate -o json
3+
/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/src/app
4+
5+
>>> [CLI] bundle validate -o json
6+
[TEST_TMP_DIR]/src/app
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trace $CLI bundle validate -o json | jq -r '.resources.apps.my_app.source_code_path'
2+
trace $CLI bundle validate -o json | jq -r '.artifacts.my_artifact.path'

acceptance/bundle/apps/artifact_and_app_same_path/src/app/test.py

Whitespace-only changes.
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+
]

bundle/config/mutator/translate_paths.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func (err ErrIsNotNotebook) Error() string {
4747
return fmt.Sprintf("file at %s is not a notebook", err.path)
4848
}
4949

50+
// seenKey is the cache key for the seen map in translateContext.
51+
// It includes both the local path and the translation mode to prevent
52+
// cross-mode cache collisions (e.g. artifact vs. workspace path translations).
53+
type seenKey struct {
54+
path string
55+
mode paths.TranslateMode
56+
}
57+
5058
type translatePaths struct{}
5159

5260
type translatePathsDashboards struct{}
@@ -76,9 +84,9 @@ func (m *translatePathsDashboards) Name() string {
7684
type translateContext struct {
7785
b *bundle.Bundle
7886

79-
// seen is a map of local paths to their corresponding remote paths.
80-
// If a local path has already been successfully resolved, we do not need to resolve it again.
81-
seen map[string]string
87+
// seen is a map of (local path, translation mode) pairs to their corresponding remote paths.
88+
// If a local path has already been successfully resolved for a given mode, we do not need to resolve it again.
89+
seen map[seenKey]string
8290

8391
// remoteRoot is the root path of the remote workspace.
8492
// It is equal to ${workspace.file_path} for regular deployments.
@@ -135,7 +143,8 @@ func (t *translateContext) rewritePath(
135143

136144
// Local path is relative to the directory the resource was defined in.
137145
localPath := filepath.Join(dir, input)
138-
if interp, ok := t.seen[localPath]; ok {
146+
key := seenKey{path: localPath, mode: opts.Mode}
147+
if interp, ok := t.seen[key]; ok {
139148
return interp, nil
140149
}
141150

@@ -181,7 +190,7 @@ func (t *translateContext) rewritePath(
181190
return "", err
182191
}
183192

184-
t.seen[localPath] = interp
193+
t.seen[key] = interp
185194
return interp, nil
186195
}
187196

@@ -337,7 +346,7 @@ func applyTranslations(ctx context.Context, b *bundle.Bundle, t *translateContex
337346
func (m *translatePaths) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
338347
t := &translateContext{
339348
b: b,
340-
seen: make(map[string]string),
349+
seen: make(map[seenKey]string),
341350
skipLocalFileValidation: b.SkipLocalFileValidation,
342351
}
343352

@@ -354,7 +363,7 @@ func (m *translatePaths) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
354363
func (m *translatePathsDashboards) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
355364
t := &translateContext{
356365
b: b,
357-
seen: make(map[string]string),
366+
seen: make(map[seenKey]string),
358367
skipLocalFileValidation: b.SkipLocalFileValidation,
359368
}
360369

0 commit comments

Comments
 (0)