fix: update unique key

This commit is contained in:
tao.chen
2026-08-14 13:44:57 +08:00
parent 7330f313ff
commit c45687ef18
5 changed files with 25 additions and 12 deletions
+1
View File
@@ -413,6 +413,7 @@ async def delete_resource(
await soft_delete_object(resource.storage_object_id, request, session)
resource.status = "deleted"
resource.deleted_at = datetime.now(UTC).replace(tzinfo=None)
resource.is_deleted = 1
return {
"request_id": context.request_id,
"data": {"resource_id": resource_id, "status": "deleted"},
+23 -3
View File
@@ -504,10 +504,7 @@ async def create_script_record(
)
try:
session.add(storage_object)
session.add(script)
await session.flush()
await session.refresh(storage_object)
await session.refresh(script)
except Exception:
# Best-effort compensating cleanup: remove the Jupyter file we
# just created so a failed flush does not leave an orphan on disk.
@@ -522,6 +519,27 @@ async def create_script_record(
f"after DB flush error: {cleanup_exc.status_code} {cleanup_exc.detail}"
)
raise
await session.refresh(storage_object)
try:
session.add(script)
await session.flush()
except Exception:
# If the Scripts row fails, the active transaction rolls back the
# StorageObjects insert as well because both share the same session.
# Still attempt to remove the Jupyter file we just pushed.
try:
await runtime_client.delete_file(workspace_id, name=jupyter_path)
except RuntimeClientError as cleanup_exc:
if cleanup_exc.status_code == 404:
pass
else:
logger.warning(
f"failed to clean up Jupyter file {jupyter_path} "
f"after DB flush error: {cleanup_exc.status_code} {cleanup_exc.detail}"
)
raise
await session.refresh(script)
return script, storage_object
@@ -975,6 +993,7 @@ async def delete_workspace_directory(
)
if script is not None:
script.status = "deleted"
script.is_deleted = 1
script.deleted_at = datetime.now(UTC).replace(tzinfo=None)
deleted_scripts += 1
descendant.object_status = "deleted"
@@ -1287,6 +1306,7 @@ async def delete_script(
script.status = "deleted"
script.deleted_at = datetime.now(UTC).replace(tzinfo=None)
script.is_deleted = 1
return {
"request_id": context.request_id,
"data": {
+1
View File
@@ -603,6 +603,7 @@ async def soft_delete_object(
item.trash_key = trash_key
item.object_status = "deleted"
item.deleted_at = _utcnow_naive()
item.is_deleted = 1
return {
"data": {
"storage_object_id": storage_object_id,