Develop #16

Merged
tao.chen merged 273 commits from develop into main 2026-08-21 10:42:09 +08:00
5 changed files with 25 additions and 12 deletions
Showing only changes of commit c45687ef18 - Show all commits
+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,
-8
View File
@@ -19,14 +19,6 @@ class Scripts(Base):
"visibility",
"status",
),
Index("uk_scripts_current_object", "current_object_id", unique=True),
Index(
"uk_scripts_workspace_name",
"workspace_id",
"script_name",
"script_type",
unique=True,
),
{"comment": "可执行 Python/Notebook 脚本"},
)
-1
View File
@@ -131,7 +131,6 @@ class DataResources(Base):
"visibility",
"status",
),
Index("uk_data_resources_object", "storage_object_id", unique=True),
{"comment": "数据资源"},
)