clean-user-exports: prevent crash when missing directory (#54406)

This commit is contained in:
Valentin Deniaud 2021-05-31 17:55:33 +02:00
parent 78b07aa497
commit 434a328bb5
2 changed files with 6 additions and 0 deletions

View File

@ -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)

View File

@ -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()