From 3094a47298a066b4f3dc226d54699fafe26eaf46 Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Thu, 13 Aug 2026 11:48:24 +0800 Subject: [PATCH] fix: path error --- backend/src/backend/scripts.py | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/backend/src/backend/scripts.py b/backend/src/backend/scripts.py index da047f0..c7545b4 100644 --- a/backend/src/backend/scripts.py +++ b/backend/src/backend/scripts.py @@ -424,14 +424,21 @@ async def create_script_record( workspace_id = context.workspace.workspace_id content_hash = hashlib.sha256(content).hexdigest() size_bytes = len(content) - if parent_ulid: - try: - await runtime_client.ensure_directory(workspace_id, f"{user_id}/{parent_ulid}") - except RuntimeClientError as exc: - raise HTTPException( - status_code=exc.status_code, - detail=exc.detail, - ) from exc + # Jupyter Contents API PUT does not create intermediate directories. + # Make sure the user's own subfolder exists at the Jupyter level before + # we try to write into it; on nested creates, also ensure the parent + # directory under it. ensure_directory is idempotent (GET-first pattern). + try: + await runtime_client.ensure_directory(workspace_id, user_id) + if parent_ulid: + await runtime_client.ensure_directory( + workspace_id, f"{user_id}/{parent_ulid}" + ) + except RuntimeClientError as exc: + raise HTTPException( + status_code=exc.status_code, + detail=exc.detail, + ) from exc try: if script_type == "notebook": @@ -826,14 +833,21 @@ async def create_workspace_directory( runtime_client = request.app.state.runtime_client workspace_id = context.workspace.workspace_id - if parent_ulid: - try: - await runtime_client.ensure_directory(workspace_id, f"{user_id}/{parent_ulid}") - except RuntimeClientError as exc: - raise HTTPException( - status_code=exc.status_code, - detail=exc.detail, - ) from exc + # Jupyter Contents API PUT does not create intermediate directories. + # Make sure the user's own subfolder exists at the Jupyter level before + # we try to write into it; on nested creates, also ensure the parent + # directory under it. ensure_directory is idempotent (GET-first pattern). + try: + await runtime_client.ensure_directory(workspace_id, user_id) + if parent_ulid: + await runtime_client.ensure_directory( + workspace_id, f"{user_id}/{parent_ulid}" + ) + except RuntimeClientError as exc: + raise HTTPException( + status_code=exc.status_code, + detail=exc.detail, + ) from exc try: await runtime_client.create_directory(workspace_id, name=jupyter_path)