From 8f43933521892a4c93dc3e13b4a5dea829962c79 Mon Sep 17 00:00:00 2001 From: Lephe Date: Mon, 20 Jul 2020 15:15:14 +0200 Subject: [PATCH] users: do not fail to remove nonexisting avatars Configuration changes and manual editions can cause this error, which is unimportant, so we can ignore it to improve stability. --- app/models/users.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/users.py b/app/models/users.py index 38af1e5..1b7f4c9 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -214,8 +214,12 @@ class Member(User): db.session.commit() # Save the new avatar im.save(V5Config.AVATARS_FOLDER + self.avatar, 'PNG') - # If nothing has failed, remove old one - os.remove(old_avatar) + # If nothing has failed, remove old one (allow failure to regularize + # exceptional situations like missing avatar or folder migration) + try: + os.remove(old_avatar) + except FileNotFoundError: + pass def get_public_data(self): """ Returns the public information of the member."""