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/bundles/7842.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix `bundle` commands failing with "unexpected change at variables.X.default" when a bundle with Python code has a variable default such as `1.0`, `1e3` or `0012345678901234`.

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] .nextchanges/README.md requires a trailing PR link on every entry and CI enforces it. Append ([#7842](https://github.com/databricks/cli/pull/7842)) after the period.

16 changes: 0 additions & 16 deletions acceptance/bundle/python/numeric-variable-default/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,16 @@
=== leading_zero

>>> uv run [UV_ARGS] -q [CLI] bundle validate -t leading_zero --output json
Error: internal error when merging output of Python mutator: unexpected change at "variables.id.default" (update)


Exit code: 1
{"default":12345678901234,"value":12345678901234}

=== float_whole

>>> uv run [UV_ARGS] -q [CLI] bundle validate -t float_whole --output json
Error: internal error when merging output of Python mutator: unexpected change at "variables.id.default" (update)


Exit code: 1
{"default":1,"value":1}

=== exponent

>>> uv run [UV_ARGS] -q [CLI] bundle validate -t exponent --output json
Error: internal error when merging output of Python mutator: unexpected change at "variables.id.default" (update)


Exit code: 1
{"default":1000,"value":1000}

=== float_fraction
Expand All @@ -39,10 +27,6 @@ Exit code: 1
=== complex

>>> uv run [UV_ARGS] -q [CLI] bundle validate -t complex --output json
Error: internal error when merging output of Python mutator: unexpected change at "variables.id.default.nested" (update)


Exit code: 1
{"default":{"nested":1},"value":{"nested":1}}

=== huge
Expand Down
14 changes: 13 additions & 1 deletion bundle/config/mutator/python/apply_python_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ func createOverrideVisitor(leftRoot, rightRoot dyn.Value) (applyPythonOutputResu
return right, nil
}
},
VisitUpdate: func(valuePath dyn.Path, _, right dyn.Value) (dyn.Value, error) {
VisitUpdate: func(valuePath dyn.Path, left, right dyn.Value) (dyn.Value, error) {
if isWholeFloatAsInt(left, right) {
return left, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[AI Generated] nit: applyPythonOutput's doc comment lists where the result differs from Python's output (kept locations, undone empty deletes). Keeping the original float when Python returns a whole int is a third case; add a bullet there?

}

if !valuePath.HasPrefix(resourcesPath) {
return dyn.InvalidValue, fmt.Errorf("unexpected change at %q (update)", valuePath.String())
}
Expand Down Expand Up @@ -211,3 +215,11 @@ func isOmitemptyDelete(left dyn.Value) bool {
return false
}
}

// isWholeFloatAsInt reports whether right is the int Python returns for the float left.
// JSON doesn't tell 1.0 from 1, so a float such as a variable default of 1.0 comes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[AI Generated] nit: It's json.Marshal in writeInputFile (python_mutator.go:506) that writes 1.0 as 1; Python's json keeps 1.0 a float. Could the comment name that cause instead of JSON itself?

// back from Python as an int.
func isWholeFloatAsInt(left, right dyn.Value) bool {
return left.Kind() == dyn.KindFloat && right.Kind() == dyn.KindInt &&
left.MustFloat() == float64(right.MustInt())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] float64(right.MustInt()) is lossy for any int64 whose absolute value exceeds 2^53: e.g. float64(9007199254740993) rounds to 9007199254740992.0, so if the original float is 9007199254740992.0 the comparison returns true and the real update is silently dropped. normalizeFloat in libs/dyn/convert/normalize.go:441 already guards against exactly this with a round-trip check. Adding && right.MustInt() == int64(left.MustFloat()) here would close the gap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[AI Generated] Above 2^53 Python returns the float's shortest decimal, not its exact value: 1234567890123456789.0 comes back as 1234567890123456800. This check accepts it, but an exact round-trip would not. Can a test pin that case?

}
20 changes: 20 additions & 0 deletions bundle/config/mutator/python/apply_python_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/databricks/cli/libs/dyn"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type applyPythonOutputTestCase struct {
Expand Down Expand Up @@ -185,6 +186,25 @@ func TestMergeOutput_disallowUpdate(t *testing.T) {
assert.EqualError(t, err, `unexpected change at "not_resource" (update)`)
}

func TestMergeOutput_wholeFloatAsInt(t *testing.T) {
input := mapOf("not_resource", dyn.V(1.0))
output := mapOf("not_resource", dyn.V(1))

merged, _, err := applyPythonOutput(input, output)

require.NoError(t, err)
assert.Equal(t, input.Get("not_resource"), merged.Get("not_resource"))
}

func TestMergeOutput_disallowFloatToDifferentInt(t *testing.T) {
input := mapOf("not_resource", dyn.V(1.5))
output := mapOf("not_resource", dyn.V(1))

_, _, err := applyPythonOutput(input, output)

assert.EqualError(t, err, `unexpected change at "not_resource" (update)`)
}

type overrideVisitorOmitemptyTestCase struct {
name string
path dyn.Path
Expand Down
Loading