fix(13): CR-03 wrap post-upload DB block in try/except to handle provider-success/DB-fail divergence
This commit is contained in:
@@ -1043,6 +1043,14 @@ async def upload_cloud_file(
|
|||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
size=resolved_size,
|
size=resolved_size,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# DB mutation block: upsert + folder-state invalidation + audit + commit.
|
||||||
|
# CR-03: Wrapped in try/except so that a DB failure after a successful
|
||||||
|
# provider upload is reported distinctly rather than propagating as an
|
||||||
|
# unhandled 500. The file IS on the provider; the metadata recording
|
||||||
|
# failed. The frontend receives a typed error so it can surface the
|
||||||
|
# discrepancy rather than silently losing the upload record.
|
||||||
|
try:
|
||||||
# Upsert item — establishes stable row identity for navigation
|
# Upsert item — establishes stable row identity for navigation
|
||||||
await upsert_cloud_item(session, user_id=str(current_user.id), resource=resource)
|
await upsert_cloud_item(session, user_id=str(current_user.id), resource=resource)
|
||||||
|
|
||||||
@@ -1084,6 +1092,23 @@ async def upload_cloud_file(
|
|||||||
)
|
)
|
||||||
|
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
except Exception:
|
||||||
|
# Provider upload succeeded but DB recording failed.
|
||||||
|
# Roll back any partial writes and return a typed error so the frontend
|
||||||
|
# knows the file is on the provider but DocuVault has no metadata record.
|
||||||
|
await session.rollback()
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_207_MULTI_STATUS,
|
||||||
|
content={
|
||||||
|
"kind": "provider_success_db_error",
|
||||||
|
"reason": "metadata_record_failed",
|
||||||
|
"provider_item_id": provider_item_id,
|
||||||
|
"message": (
|
||||||
|
"File uploaded to provider but DocuVault metadata recording failed. "
|
||||||
|
"Refresh the folder to re-sync."
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"kind": "uploaded",
|
"kind": "uploaded",
|
||||||
|
|||||||
Reference in New Issue
Block a user