From 434a328bb5059e0d91cc4a9326fe461f8ef3f8c0 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 31 May 2021 17:55:33 +0200 Subject: [PATCH] clean-user-exports: prevent crash when missing directory (#54406) --- src/authentic2/management/commands/clean-user-exports.py | 3 +++ tests/test_commands.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/authentic2/management/commands/clean-user-exports.py b/src/authentic2/management/commands/clean-user-exports.py index 652b7977c..3d4980e7e 100644 --- a/src/authentic2/management/commands/clean-user-exports.py +++ b/src/authentic2/management/commands/clean-user-exports.py @@ -27,6 +27,9 @@ class Command(BaseCommand): def handle(self, **options): path = default_storage.path('user_exports') + if not os.path.exists(path): + return + for directory in os.listdir(path): dir_path = os.path.join(path, directory) modification_timestamp = os.path.getmtime(dir_path) diff --git a/tests/test_commands.py b/tests/test_commands.py index 75fc13bee..5ecd68996 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -410,6 +410,9 @@ def test_clean_user_exports(settings, app, superuser, freezer): users = [User(username='user%s' % i) for i in range(10)] User.objects.bulk_create(users) + # export directory does not exist yet + call_command('clean-user-exports') + resp = login(app, superuser, '/manage/users/') resp = resp.click('CSV').follow() file_creation_time = now()