From b3c5e282c46efa07cbe10c61cebe099ae57a3016 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 15 Apr 2026 16:33:04 +0000 Subject: [PATCH 1/3] Fix float precision loss in jsonschema ParseFloat strconv.ParseFloat(s, 32) parses the string as a float32 and then promotes it to float64, silently losing precision. For example, "1.1" becomes 1.100000023841858 instead of 1.1. This affects users who specify number-type template variables during `databricks bundle init`. Change the bit size from 32 to 64 to preserve full float64 precision. Task: 001.md Co-authored-by: Isaac --- libs/jsonschema/utils.go | 2 +- libs/jsonschema/utils_test.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/jsonschema/utils.go b/libs/jsonschema/utils.go index b9df7da515..cb25393075 100644 --- a/libs/jsonschema/utils.go +++ b/libs/jsonschema/utils.go @@ -110,7 +110,7 @@ func fromString(s string, T Type) (any, error) { case BooleanType: v, err = strconv.ParseBool(s) case NumberType: - v, err = strconv.ParseFloat(s, 32) + v, err = strconv.ParseFloat(s, 64) case IntegerType: v, err = strconv.ParseInt(s, 10, 64) case ArrayType, ObjectType: diff --git a/libs/jsonschema/utils_test.go b/libs/jsonschema/utils_test.go index 954c723d3f..d0a46e6788 100644 --- a/libs/jsonschema/utils_test.go +++ b/libs/jsonschema/utils_test.go @@ -95,8 +95,7 @@ func TestTemplateFromString(t *testing.T) { v, err = fromString("1.1", NumberType) assert.NoError(t, err) - // Floating point conversions are not perfect - assert.Less(t, (v.(float64) - 1.1), 0.000001) + assert.Equal(t, 1.1, v) v, err = fromString("12345", IntegerType) assert.NoError(t, err) @@ -104,7 +103,7 @@ func TestTemplateFromString(t *testing.T) { v, err = fromString("123", NumberType) assert.NoError(t, err) - assert.InDelta(t, float64(123), v.(float64), 0.0001) + assert.Equal(t, float64(123), v) _, err = fromString("qrt", ArrayType) assert.EqualError(t, err, "cannot parse string as object of type array. Value of string: \"qrt\"") From f58a61252c01db0176f4fa1a6872c9fd7fc648b5 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 15 Apr 2026 16:37:52 +0000 Subject: [PATCH 2/3] Add changelog entry for float precision fix Co-authored-by: Isaac --- NEXT_CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index c196e389c0..8fc3c33c3f 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -5,5 +5,6 @@ ### CLI ### Bundles +* Fix float precision loss when parsing number-type template variables during `bundle init` (denik/random-bugfixes-3) ### Dependency updates From b6f655c7e89be69b66d35f21e795c5fb186fb757 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 22 Apr 2026 14:54:35 +0000 Subject: [PATCH 3/3] Add regression test for float precision fix Adds an acceptance test that renders a template with a number-type variable (default 1.1). Prior to the ParseFloat bit-size fix the value rendered as 1.100000023841858; with the fix it renders as 1.1. Task: 005.md Co-authored-by: Isaac --- .../number-precision/databricks_template_schema.json | 9 +++++++++ .../templates-machinery/number-precision/out.test.toml | 5 +++++ .../templates-machinery/number-precision/output.txt | 6 ++++++ .../bundle/templates-machinery/number-precision/script | 4 ++++ .../number-precision/template/number.txt.tmpl | 1 + 5 files changed, 25 insertions(+) create mode 100644 acceptance/bundle/templates-machinery/number-precision/databricks_template_schema.json create mode 100644 acceptance/bundle/templates-machinery/number-precision/out.test.toml create mode 100644 acceptance/bundle/templates-machinery/number-precision/output.txt create mode 100644 acceptance/bundle/templates-machinery/number-precision/script create mode 100644 acceptance/bundle/templates-machinery/number-precision/template/number.txt.tmpl diff --git a/acceptance/bundle/templates-machinery/number-precision/databricks_template_schema.json b/acceptance/bundle/templates-machinery/number-precision/databricks_template_schema.json new file mode 100644 index 0000000000..9a1bfb55a5 --- /dev/null +++ b/acceptance/bundle/templates-machinery/number-precision/databricks_template_schema.json @@ -0,0 +1,9 @@ +{ + "properties": { + "n": { + "type": "number", + "description": "A number variable", + "default": 1.1 + } + } +} diff --git a/acceptance/bundle/templates-machinery/number-precision/out.test.toml b/acceptance/bundle/templates-machinery/number-precision/out.test.toml new file mode 100644 index 0000000000..d560f1de04 --- /dev/null +++ b/acceptance/bundle/templates-machinery/number-precision/out.test.toml @@ -0,0 +1,5 @@ +Local = true +Cloud = false + +[EnvMatrix] + DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] diff --git a/acceptance/bundle/templates-machinery/number-precision/output.txt b/acceptance/bundle/templates-machinery/number-precision/output.txt new file mode 100644 index 0000000000..7b07f8a5b5 --- /dev/null +++ b/acceptance/bundle/templates-machinery/number-precision/output.txt @@ -0,0 +1,6 @@ + +>>> [CLI] bundle init . +✨ Successfully initialized template + +>>> cat number.txt +n: 1.1 diff --git a/acceptance/bundle/templates-machinery/number-precision/script b/acceptance/bundle/templates-machinery/number-precision/script new file mode 100644 index 0000000000..e15c9e54dc --- /dev/null +++ b/acceptance/bundle/templates-machinery/number-precision/script @@ -0,0 +1,4 @@ +trace $CLI bundle init . + +trace cat number.txt +rm number.txt diff --git a/acceptance/bundle/templates-machinery/number-precision/template/number.txt.tmpl b/acceptance/bundle/templates-machinery/number-precision/template/number.txt.tmpl new file mode 100644 index 0000000000..cb1344deb3 --- /dev/null +++ b/acceptance/bundle/templates-machinery/number-precision/template/number.txt.tmpl @@ -0,0 +1 @@ +n: {{ .n }}