Skip to content

Commit dbf9701

Browse files
fix(staging): reject byte-valued local path entries
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
1 parent 5e78ed6 commit dbf9701

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎examples/staging_ingestion.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
2. Set the FILEPATH constant to the path of a file that will be uploaded (this example assumes its a CSV file)
3131
3. Run this file
3232
33-
Note: staging_allowed_local_path accepts a path string or a list of path strings.
33+
Note: staging_allowed_local_path accepts a path string or a list of strings or
34+
os.PathLike objects that resolve to strings.
3435
"""
3536

3637
INGESTION_USER = "some.user@example.com"

‎src/databricks/sql/backend/kernel/client.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,19 @@ def execute_command(
582582
allowed_paths, (str, list)
583583
):
584584
raise ProgrammingError(
585-
"staging_allowed_local_path must be a string or a list of paths"
585+
"staging_allowed_local_path must be a string or a list of strings or os.PathLike objects"
586586
)
587587
if isinstance(allowed_paths, str):
588588
allowed_paths = [allowed_paths]
589589
try:
590590
normalized_paths = [
591-
os.fsdecode(path) for path in allowed_paths or []
591+
os.fspath(path) for path in allowed_paths or []
592592
]
593+
if any(not isinstance(path, str) for path in normalized_paths):
594+
raise TypeError("Local paths must resolve to strings")
593595
except (TypeError, ValueError) as exc:
594596
raise ProgrammingError(
595-
"staging_allowed_local_path must be a string or a list of paths"
597+
"staging_allowed_local_path must be a string or a list of strings or os.PathLike objects"
596598
) from exc
597599
set_paths(normalized_paths)
598600
elif staging_verb is not None:

‎tests/unit/test_kernel_client.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,16 @@ def test_execute_command_forwards_allowed_local_paths(
862862

863863
@pytest.mark.parametrize(
864864
"allowed",
865-
[123, [object()], Path("/tmp/files"), ("/tmp/files",), (), {"/tmp/files": True}],
865+
[
866+
123,
867+
[object()],
868+
[b"/tmp/files"],
869+
["/tmp/files", b"/tmp/other"],
870+
Path("/tmp/files"),
871+
("/tmp/files",),
872+
(),
873+
{"/tmp/files": True},
874+
],
866875
)
867876
@pytest.mark.parametrize(
868877
"operation",

0 commit comments

Comments
 (0)