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

Abierto
#1,272 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@deepan-crypto ya está trabajando en esto.

Desde el 3/10/2026.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Comienza reproduciendo WorkspaceClient.files.download con el x-forwarded-access-token y compáralo con la solicitud GET directa descrita en el issue. Inspecciona databricks/sdk/mixins/files.py, databricks/sdk/service/files.py, databricks/sdk/core.py y databricks/sdk/_base_client.py siguiendo la ruta del traceback. Se considera terminado cuando la descarga del cliente funciona con el token de la aplicación desplegada y existe cobertura para el comportamiento del ámbito de permisos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
577
Forks
229
Merge medio
40 min
PR fusionados (30 d)
12

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de databricks/databricks-sdk-py

Todos los issues de databricks/databricks-sdk-py

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.