From 3881237c6f9c3faf226c45b8ac453c748e849d29 Mon Sep 17 00:00:00 2001 From: Greg Kaleka Date: Thu, 17 Apr 2025 11:03:04 -0400 Subject: [PATCH] Fix issue with user avatars (#1757) --- users/models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/users/models.py b/users/models.py index 06fa80eb..99ff6e59 100644 --- a/users/models.py +++ b/users/models.py @@ -1,6 +1,7 @@ import uuid import logging import os +from contextlib import suppress import requests from django.conf import settings @@ -17,6 +18,7 @@ from django.dispatch import receiver from django.utils import timezone from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ +from imagekit.exceptions import MissingSource from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFill @@ -286,12 +288,9 @@ class User(BaseUser): def get_thumbnail_url(self): # convenience method for templates - if ( - self.image - and self.image.storage.exists(self.image.name) - and self.image_thumbnail - ): - return getattr(self.image_thumbnail, "url", None) + if self.image and self.image_thumbnail: + with suppress(AttributeError, MissingSource): + return getattr(self.image_thumbnail, "url", None) @property def github_profile_url(self):