From 7b9136d9516f2e3a7a95a8c1b0be208171990604 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Tue, 19 Jan 2021 09:15:43 +0100 Subject: [PATCH] take into account user.profile_picture can be None --- app/api/views/user_info.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/api/views/user_info.py b/app/api/views/user_info.py index 935b63d4..380f2634 100644 --- a/app/api/views/user_info.py +++ b/app/api/views/user_info.py @@ -54,12 +54,13 @@ def update_user_info(): if "profile_picture" in data: if data["profile_picture"] is None: if user.profile_picture_id: + file = user.profile_picture + if file: + File.delete(file.id) + s3.delete(file.path) + user.profile_picture_id = None db.session.flush() - - file = user.profile_picture - File.delete(file.id) - s3.delete(file.path) else: raw_data = base64.decodebytes(data["profile_picture"].encode()) file_path = random_string(30)