Skip to content

Commit ec50afd

Browse files
committed
fix: select_spark_version(latest=True) no longer implicitly filters to scala 2.12
The scala parameter defaulted to "2.12" and the filter applied it unconditionally, so select_spark_version(latest=True) silently narrowed to scala-2.12 runtimes before picking the latest instead of considering every scala version. This diverged from the Go SDK this logic is ported from: Go's SparkVersionRequest.Scala has no default, so an unset Scala is "" (its zero value), and strings.Contains(key, "-scala"+"") matches every version's key -- Go's real default is no scala filter. Changed the Python default to "" and only apply the filter when scala is truthy, matching the Go SDK's actual behavior. Callers who explicitly pass scala="2.12" are unaffected. Fixes #1487
1 parent f5b08c0 commit ec50afd

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

databricks/sdk/mixins/compute.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def select_spark_version(
8181
ml: bool = False,
8282
genomics: bool = False,
8383
gpu: bool = False,
84-
scala: str = "2.12",
84+
scala: str = "",
8585
spark_version: str = None,
8686
photon: bool = False,
8787
graviton: bool = False,
@@ -95,17 +95,19 @@ def select_spark_version(
9595
:param genomics: bool
9696
:param gpu: bool
9797
:param scala: str
98+
Scala version to filter on, e.g. "2.12" or "2.13". Leave empty (the default) to
99+
consider every Scala version, matching the Go SDK's zero-value behavior.
98100
:param spark_version: str
99101
:param photon: bool
100102
:param graviton: bool
101103
102104
:returns: `spark_version` compatible string
103105
"""
104-
# Logic ported from https://github.com/databricks/databricks-sdk-go/blob/main/service/compute/spark_version.go
106+
# Logic ported from https://github.com/databricks/databricks-sdk-go/blob/main/service/compute/ext_spark_version.go
105107
versions = []
106108
sv = self.spark_versions()
107109
for version in sv.versions:
108-
if "-scala" + scala not in version.key:
110+
if scala and "-scala" + scala not in version.key:
109111
continue
110112
matches = (
111113
("apache-spark-" not in version.key)

tests/test_compute_mixins.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
import json
2+
13
import pytest
24

35
from databricks.sdk.mixins.compute import SemVer
46

7+
SPARK_VERSIONS_RESPONSE = {
8+
"versions": [
9+
{"key": "16.4.x-scala2.12", "name": "16.4"},
10+
{"key": "18.2.x-scala2.13", "name": "18.2"},
11+
]
12+
}
13+
514

615
@pytest.mark.parametrize(
716
"given,expected",
@@ -40,3 +49,25 @@ def test_sorting_semver():
4049
SemVer(1, 0, 0),
4150
SemVer(12, 0, 0),
4251
]
52+
53+
54+
def test_select_spark_version_latest_ignores_scala_by_default(w, requests_mock):
55+
# Regression test for https://github.com/databricks/databricks-sdk-py/issues/1487:
56+
# select_spark_version(latest=True) implicitly filtered to the "2.12" default
57+
# scala version before picking the latest, instead of considering every scala
58+
# version like the Go SDK it's ported from does.
59+
requests_mock.get(
60+
"http://localhost/api/2.1/clusters/spark-versions",
61+
text=json.dumps(SPARK_VERSIONS_RESPONSE),
62+
)
63+
64+
assert w.clusters.select_spark_version(latest=True) == "18.2.x-scala2.13"
65+
66+
67+
def test_select_spark_version_latest_still_honors_an_explicit_scala(w, requests_mock):
68+
requests_mock.get(
69+
"http://localhost/api/2.1/clusters/spark-versions",
70+
text=json.dumps(SPARK_VERSIONS_RESPONSE),
71+
)
72+
73+
assert w.clusters.select_spark_version(latest=True, scala="2.12") == "16.4.x-scala2.12"

0 commit comments

Comments
 (0)