diff --git a/zerver/lib/export.py b/zerver/lib/export.py index d50e762aca..bdc674fbab 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -1461,7 +1461,15 @@ def import_uploads_local(import_dir: Path, processing_avatars: bool=False, for record in records: if record['s3_path'].endswith('.original'): user_profile = get_user_profile_by_id(record['user_profile_id']) - # If medium sized avatar does not exist, this creates it using the original image + avatar_path = user_avatar_path_from_ids(user_profile.id, record['realm_id']) + medium_file_path = os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars", + avatar_path) + '-medium.png' + if os.path.exists(medium_file_path): + # We remove the image here primarily to deal with + # issues when running the import script multiple + # times in development (where one might reuse the + # same realm ID from a previous iteration). + os.remove(medium_file_path) upload_backend.ensure_medium_avatar_image(user_profile=user_profile) def import_uploads_s3(bucket_name: str, import_dir: Path, processing_avatars: bool=False,