fix: update_script rewrite metadata

This commit is contained in:
tao.chen
2026-08-20 09:57:46 +08:00
parent 3b0229f018
commit d8a31bde95
2 changed files with 176 additions and 7 deletions
+28 -7
View File
@@ -1196,13 +1196,34 @@ async def update_script(
) from exc
script.updated_at = datetime.now(UTC).replace(tzinfo=None)
storage_data = {
"storage_object_id": script.current_object_id,
"relative_path": jupyter_path,
"object_key": f"{workspace_id}/{jupyter_path}",
"content_hash": hashlib.sha256(content).hexdigest(),
"size_bytes": len(content),
}
content_hash = hashlib.sha256(content).hexdigest()
size_bytes = len(content)
relative_path = f"workspace/{jupyter_path}"
# Persist the new content fingerprint so cache/dedup/hash checks
# downstream see the post-edit values. Filename is fixed in
# update_script, so object_key / path_hash are unchanged — only the
# body-derived fields move. relative_path is re-derived to keep the
# response in sync with the workspace-prefixed convention used at
# create time.
if storage_object is not None:
storage_object.content_hash = content_hash
storage_object.size_bytes = size_bytes
storage_object.relative_path = relative_path
await session.flush()
await session.refresh(storage_object)
storage_data: StorageObjects | dict[str, Any] = storage_object
else:
# Jupyter-only script: no StorageObjects row to update, but the
# response still needs the workspace-prefixed path shape so the
# frontend's slice(2) reducer produces the expected basename.
storage_data = {
"storage_object_id": script.current_object_id,
"relative_path": relative_path,
"object_key": f"{workspace_id}/{jupyter_path}",
"content_hash": content_hash,
"size_bytes": size_bytes,
}
return {
"request_id": context.request_id,
"data": script_payload(script, storage_data),