mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
management: Don't use sys.exit(1).
Using sys.exit in a management command makes it impossible
to unit test the code in question. The correct approach to do the same
thing in Django management commands is to raise CommandError.
Followup of b570c0dafa
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from zerver.lib.actions import do_delete_old_unclaimed_attachments
|
||||
from zerver.models import get_old_unclaimed_attachments
|
||||
@@ -36,8 +36,7 @@ class Command(BaseCommand):
|
||||
|
||||
print("")
|
||||
if not options["for_real"]:
|
||||
print("This was a dry run. Pass -f to actually delete.")
|
||||
exit(1)
|
||||
raise CommandError("This was a dry run. Pass -f to actually delete.")
|
||||
|
||||
do_delete_old_unclaimed_attachments(delta_weeks)
|
||||
print("")
|
||||
|
||||
Reference in New Issue
Block a user