<commit_before>from django.core.management.base import BaseCommand, CommandError
from django.db.models import get_models

class Command(BaseCommand):
    help = 'Deletes all objects'

    def handle(self, *args, **options):
        for model in get_models():
            model.objects.all().delete()
<commit_msg>delete_all_objects was made more robust<commit_after>from django.core.management.base import BaseCommand, CommandError
from django.db.models import get_models

class Command(BaseCommand):
    help = 'Deletes all objects'

    def handle(self, *args, **options):
        failed_somewhere = False
        max_tries = 100

        while failed_somewhere and max_tries > 0:
            # some deletions may trigger other deletions and fail; we'll just try many times

            max_tries -= 1

            for model in get_models():
                try:
                    model.objects.all().delete()
                except:
                    failed_somewhere = True

        if max_tries == 0:
            raise Exception("Giving up after 100 tries")
{'fraction_non_alphanumeric': 0.07981220657276995, 'fraction_numerical': 0.008450704225352112, 'mean_word_length': 2.427652733118971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7591874', 'n_tokens_mistral': 295, 'n_tokens_neox': 270, 'n_words': 89}