fix: pollStatus 已 active 的素材跳过远程查询,防止跨项目素材被误删
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 6m31s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 6m31s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ae0e2d4365
commit
947d154118
@ -3446,7 +3446,8 @@ def asset_poll_status_view(request, asset_id):
|
|||||||
except Asset.DoesNotExist:
|
except Asset.DoesNotExist:
|
||||||
return Response({'error': '素材不存在'}, status=status.HTTP_404_NOT_FOUND)
|
return Response({'error': '素材不存在'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
if asset.remote_asset_id:
|
# 已经 active 且有 URL 的素材跳过远程查询(避免跨项目素材被误删)
|
||||||
|
if asset.remote_asset_id and asset.status != 'active':
|
||||||
from utils import assets_client
|
from utils import assets_client
|
||||||
from utils.assets_client import AssetsAPIError
|
from utils.assets_client import AssetsAPIError
|
||||||
try:
|
try:
|
||||||
@ -3463,7 +3464,6 @@ def asset_poll_status_view(request, asset_id):
|
|||||||
asset.save(update_fields=['status', 'url', 'error_message'])
|
asset.save(update_fields=['status', 'url', 'error_message'])
|
||||||
except AssetsAPIError as e:
|
except AssetsAPIError as e:
|
||||||
error_str = str(e)
|
error_str = str(e)
|
||||||
# 火山返回素材不存在 → 删除本地记录
|
|
||||||
if 'not found' in error_str.lower() or 'NotFound' in e.code or 'NotExist' in e.code:
|
if 'not found' in error_str.lower() or 'NotFound' in e.code or 'NotExist' in e.code:
|
||||||
asset.delete()
|
asset.delete()
|
||||||
return Response({'status': 'deleted', 'message': '素材在云端已被删除'})
|
return Response({'status': 'deleted', 'message': '素材在云端已被删除'})
|
||||||
@ -3473,7 +3473,6 @@ def asset_poll_status_view(request, asset_id):
|
|||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_str = str(e)
|
error_str = str(e)
|
||||||
# 空响应 / JSON 解析失败 = 火山已删除该素材
|
|
||||||
if 'Expecting value' in error_str or 'JSONDecodeError' in type(e).__name__:
|
if 'Expecting value' in error_str or 'JSONDecodeError' in type(e).__name__:
|
||||||
logger.info('Asset %s appears deleted on remote (empty response), removing local record', asset.remote_asset_id)
|
logger.info('Asset %s appears deleted on remote (empty response), removing local record', asset.remote_asset_id)
|
||||||
asset.delete()
|
asset.delete()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user