Skip to content

Commit 7513d9c

Browse files
committed
fix: treat an empty preset ID as the default
An empty string resolves to the organization default on the server but still changed the session reuse identity and pool eligibility.
1 parent b14d7ef commit 7513d9c

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ users may find useful:
349349
of WherobotsDB available to your subscription.
350350
* `environment_preset_id`: the ID of one of your organization's
351351
environment presets to start the SQL session with. Defaults to your
352-
organization's default preset.
352+
organization's default preset. When the preset pins a WherobotsDB
353+
version and `version` is omitted, the session uses the preset's
354+
version; an explicit `version` takes precedence.
353355
* `environment_override_preset_id`: the ID of one of your organization's
354356
override presets to layer on the environment preset. Defaults to your
355357
organization's default override preset.

‎tests/test_driver.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,43 @@ def test_omitted_presets_leave_the_body_unchanged(self, mock_post, mock_get):
128128
"sessionType": "multi",
129129
}
130130

131+
@pytest.mark.parametrize(
132+
("param", "field"),
133+
[
134+
("environment_preset_id", "environmentPresetId"),
135+
("environment_override_preset_id", "environmentOverridePresetId"),
136+
],
137+
)
138+
@pytest.mark.parametrize("value", [None, ""])
139+
@patch("wherobots.db.driver.requests.get")
140+
@patch("wherobots.db.driver.requests.post")
141+
def test_each_unset_preset_is_omitted(
142+
self, mock_post, mock_get, param, field, value
143+
):
144+
"""An empty ID means the default, so it must not change session reuse."""
145+
kwargs = _run_connect(mock_post, mock_get, **{param: value})
146+
assert field not in kwargs["json"]
147+
148+
@pytest.mark.parametrize(
149+
("param", "field"),
150+
[
151+
("environment_preset_id", "environmentPresetId"),
152+
("environment_override_preset_id", "environmentOverridePresetId"),
153+
],
154+
)
155+
@patch("wherobots.db.driver.requests.get")
156+
@patch("wherobots.db.driver.requests.post")
157+
def test_each_preset_is_sent_alone(self, mock_post, mock_get, param, field):
158+
kwargs = _run_connect(mock_post, mock_get, **{param: "p-1"})
159+
assert kwargs["json"][field] == "p-1"
160+
assert (
161+
len(
162+
{"environmentPresetId", "environmentOverridePresetId"}
163+
& kwargs["json"].keys()
164+
)
165+
== 1
166+
)
167+
131168

132169
class TestConnectSessionKey:
133170
"""session_key reaches the API, and the API's fallback reaches the caller."""

‎wherobots/db/driver.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ def connect(
248248
body["sessionKey"] = session_key
249249
if session_key_exclusive:
250250
body["sessionKeyExclusive"] = True
251-
if environment_preset_id is not None:
251+
# An empty ID means the default, and must not split session reuse from it.
252+
if environment_preset_id:
252253
body["environmentPresetId"] = environment_preset_id
253-
if environment_override_preset_id is not None:
254+
if environment_override_preset_id:
254255
body["environmentOverridePresetId"] = environment_override_preset_id
255256

256257
try:

0 commit comments

Comments
 (0)