Skip to content

Commit c07beb1

Browse files
SEA Session Configuration Fix: Explicitly convert values to str (#620)
* explicitly convert session conf values to str Signed-off-by: varun-edachali-dbx <[email protected]> * add unit test for filter_session_conf Signed-off-by: varun-edachali-dbx <[email protected]> * re-introduce unit test for string values of session conf Signed-off-by: varun-edachali-dbx <[email protected]> * ensure Dict return from _filter_session_conf Signed-off-by: varun-edachali-dbx <[email protected]> --------- Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent 1a0575a commit c07beb1

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/databricks/sql/backend/sea/backend.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@
5050

5151

5252
def _filter_session_configuration(
53-
session_configuration: Optional[Dict[str, str]]
54-
) -> Optional[Dict[str, str]]:
53+
session_configuration: Optional[Dict[str, Any]],
54+
) -> Dict[str, str]:
5555
if not session_configuration:
56-
return None
56+
return {}
5757

5858
filtered_session_configuration = {}
5959
ignored_configs: Set[str] = set()
6060

6161
for key, value in session_configuration.items():
6262
if key.upper() in ALLOWED_SESSION_CONF_TO_DEFAULT_VALUES_MAP:
63-
filtered_session_configuration[key.lower()] = value
63+
filtered_session_configuration[key.lower()] = str(value)
6464
else:
6565
ignored_configs.add(key)
6666

@@ -188,7 +188,7 @@ def max_download_threads(self) -> int:
188188

189189
def open_session(
190190
self,
191-
session_configuration: Optional[Dict[str, str]],
191+
session_configuration: Optional[Dict[str, Any]],
192192
catalog: Optional[str],
193193
schema: Optional[str],
194194
) -> SessionId:

tests/unit/test_sea_backend.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,71 @@ def test_utility_methods(self, sea_client):
624624
assert description[1][1] == "INT" # type_code
625625
assert description[1][6] is False # null_ok
626626

627+
def test_filter_session_configuration(self):
628+
"""Test that _filter_session_configuration converts all values to strings."""
629+
session_config = {
630+
"ANSI_MODE": True,
631+
"statement_timeout": 3600,
632+
"TIMEZONE": "UTC",
633+
"enable_photon": False,
634+
"MAX_FILE_PARTITION_BYTES": 128.5,
635+
"unsupported_param": "value",
636+
"ANOTHER_UNSUPPORTED": 42,
637+
}
638+
639+
result = _filter_session_configuration(session_config)
640+
641+
# Verify result is not None
642+
assert result is not None
643+
644+
# Verify all returned values are strings
645+
for key, value in result.items():
646+
assert isinstance(
647+
value, str
648+
), f"Value for key '{key}' is not a string: {type(value)}"
649+
650+
# Verify specific conversions
651+
expected_result = {
652+
"ansi_mode": "True", # boolean True -> "True", key lowercased
653+
"statement_timeout": "3600", # int -> "3600", key lowercased
654+
"timezone": "UTC", # string -> "UTC", key lowercased
655+
"enable_photon": "False", # boolean False -> "False", key lowercased
656+
"max_file_partition_bytes": "128.5", # float -> "128.5", key lowercased
657+
}
658+
659+
assert result == expected_result
660+
661+
# Test with None input
662+
assert _filter_session_configuration(None) == {}
663+
664+
# Test with only unsupported parameters
665+
unsupported_config = {
666+
"unsupported_param1": "value1",
667+
"unsupported_param2": 123,
668+
}
669+
result = _filter_session_configuration(unsupported_config)
670+
assert result == {}
671+
672+
# Test case insensitivity for keys
673+
case_insensitive_config = {
674+
"ansi_mode": "false", # lowercase key
675+
"STATEMENT_TIMEOUT": 7200, # uppercase key
676+
"TiMeZoNe": "America/New_York", # mixed case key
677+
}
678+
result = _filter_session_configuration(case_insensitive_config)
679+
expected_case_result = {
680+
"ansi_mode": "false",
681+
"statement_timeout": "7200",
682+
"timezone": "America/New_York",
683+
}
684+
assert result == expected_case_result
685+
686+
# Verify all values are strings in case insensitive test
687+
for key, value in result.items():
688+
assert isinstance(
689+
value, str
690+
), f"Value for key '{key}' is not a string: {type(value)}"
691+
627692
def test_results_message_to_execute_response_is_staging_operation(self, sea_client):
628693
"""Test that is_staging_operation is correctly set from manifest.is_volume_operation."""
629694
# Test when is_volume_operation is True

0 commit comments

Comments
 (0)