[ISSUE] Workspace Client files.download fails in Databricks App

Đang mở
#1,272 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@deepan-crypto đang làm issue này rồi.

Từ ngày 3/10/2026.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
api, authentication

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện WorkspaceClient.files.download với x-forwarded-access-token và so sánh với yêu cầu GET trực tiếp được mô tả trong issue. Kiểm tra databricks/sdk/mixins/files.py, databricks/sdk/service/files.py, databricks/sdk/core.py và databricks/sdk/_base_client.py theo đường dẫn traceback. Được xem là hoàn tất khi việc tải xuống của client hoạt động với token của ứng dụng đã triển khai và có coverage cho hành vi của phạm vi quyền.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description
When using the files.download method in the Workspace Client, this works locally with an injected user access token but failing with the downscoped user-authorisation x-forwarded-access-token.
When calling the GET API directly at <host>/api/2.0/fs/files this works fine for both local and deployed Databricks App.

Reproduction

@router.get("/get_image/{image_path:path}")
async def get_databricks_image(
    request: Request,
    image_path: str):
    from databricks.sdk.core import Config
    from Databricks.sdk import WorkspaceClient
    import jwt
    import databricks
    
    access_token = request.headers.get("x-forwarded-access-token")

    try:
        cfg = Config(host=<HOST>,
            token=access_token,
            auth_type="pat",
            )
       
        w = WorkspaceClient(config=cfg)
 
        logger.info(f"Fetching image from Databricks: {image_path}")
 
        resp: DownloadResponse = w.files.download(image_path)
        # Get binary image content
        image_bytes = resp.contents.read()
 
        # Convert binary image to base64 string
        image_base64 = base64.b64encode(image_bytes).decode('utf-8')
           
    except Exception as e:
        logger.error(f"Full traceback:\n{traceback.format_exc()}")
 
        return JSONResponse(
            status_code=500,
            content={"error": str(e)},
        )
   
    return JSONResponse(content={"image_data": image_base64, "path": image_path})

Expected behavior
This works when testing locally with a Workspace level Admin account by using Databricks auth login and then adding a middleware in FastAPI to inject the x-forwarded-access-token by reading the access_token from the local ~/.databricks/token-cache.json file.
When deployed to Databricks App, this errors out:
databricks.sdk.errors.platform.PermissionDenied: Provided OAuth token does not have required scopes

Is it a regression?
Not a regression AFAIK

Debug Logs

2026-02-18 04:26:46,783 [ERROR] Full traceback: Traceback (most recent call last):   File "/app/python/source_code/routes/v1/image_search.py", line 271, in get_databricks_image     resp: DownloadResponse = w.files.download(image_path)                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/mixins/files.py", line 800, in download     return super().download(file_path)            ^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/service/files.py", line 881, in download     res = self._api.do(           ^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/core.py", line 86, in do     return self._api_client.do(            ^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/_base_client.py", line 199, in do     response = call(                ^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/retries.py", line 59, in wrapper     raise err   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/retries.py", line 38, in wrapper     return func(*args, **kwargs)            ^^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/_base_client.py", line 301, in _perform     raise error from None

Other Information
Databricks SDK version: 0.83.0

Additional context
Pair programming session done with Databricks engineer Naim on 13th of February 2026 to diagnose issue. Implementation changed to raw HTTP request instead of workspace client.

Ngôn ngữ chính
Python
Star
577
Fork
229
Merge trung bình
40 phút
Pull request đã merge (30 ngày)
12

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của databricks/databricks-sdk-py

Tất cả issue của databricks/databricks-sdk-py

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.