Skip to content

Wrap bulk delete loop in transaction #4250

@hannaseithe

Description

@hannaseithe

Short description

BulkDeletingView.post() calls .delete() on objects one by one inside a loop without wrapping in a transaction. If the 51st item raises ProtectedError, the first 50 are already gone with no rollback.

Suggested Solution

# Fix: add @transaction.atomic to post(), or wrap the loop
with transaction.atomic():
    for content_object in self.get_queryset():
        ...
        content_object.delete()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions