diff --git a/corehq/form_processor/models/forms.py b/corehq/form_processor/models/forms.py index b53dde8db9ec..52b12e52299e 100644 --- a/corehq/form_processor/models/forms.py +++ b/corehq/form_processor/models/forms.py @@ -403,9 +403,10 @@ def hard_delete_forms( for db_name, split_form_ids in split_list_by_db_partition(form_ids): # cascade should delete the operations query = self.using(db_name).filter(domain=domain, form_id__in=split_form_ids) - if return_ids: - found_forms = list(query.values_list('form_id', flat=True)) - _, deleted_models = query.delete() + with transaction.atomic(): + if return_ids: + found_forms = list(query.values_list('form_id', flat=True)) + _, deleted_models = query.delete() deleted_count += deleted_models.get(self.model._meta.label, 0) if return_ids: deleted_ids.extend(found_forms)