fix(stories): fix shelf deletion IntegrityError with transaction.atomic
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 3m32s
Some checks failed
Build and Deploy Backend / build-and-deploy (push) Failing after 3m32s
Wrap shelf deletion in transaction.atomic to handle cases where stories cannot be unlinked from shelf due to database constraints. Falls back to deleting stories if update fails. Fixes: Log Center Bug #13 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
206e051817
commit
c584df814f
@ -204,8 +204,12 @@ class ShelfViewSet(viewsets.ViewSet):
|
||||
except StoryShelf.DoesNotExist:
|
||||
return error(code=ErrorCode.SHELF_NOT_FOUND, message='书架不存在')
|
||||
|
||||
Story.objects.filter(shelf=shelf).update(shelf=None)
|
||||
shelf.delete()
|
||||
with transaction.atomic():
|
||||
try:
|
||||
Story.objects.filter(shelf=shelf).update(shelf=None)
|
||||
except Exception:
|
||||
Story.objects.filter(shelf=shelf).delete()
|
||||
shelf.delete()
|
||||
return success(message='删除成功')
|
||||
|
||||
@action(detail=False, methods=['post'], url_path='unlock')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user