From 8d224ecbeec0e7771c049c3487512338bdbbdbc3 Mon Sep 17 00:00:00 2001 From: Neo <54811660+neooriginal@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:15:14 +0100 Subject: [PATCH 1/2] Update storage.py --- backend/utils/other/storage.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/utils/other/storage.py b/backend/utils/other/storage.py index a9276c2b04..a5d3c3ddb0 100644 --- a/backend/utils/other/storage.py +++ b/backend/utils/other/storage.py @@ -11,7 +11,7 @@ from google.oauth2 import service_account from google.cloud.storage import transfer_manager from google.cloud.exceptions import NotFound as BlobNotFound -from google.cloud.exceptions import NotFound +from google.cloud.exceptions import NotFound, Forbidden from database.redis_db import cache_signed_url, get_cached_signed_url from utils import encryption @@ -47,11 +47,17 @@ def upload_profile_audio(file_path: str, uid: str): def get_user_has_speech_profile(uid: str, max_age_days: int = None) -> bool: + if not speech_profiles_bucket: + return False bucket = storage_client.bucket(speech_profiles_bucket) blob = bucket.blob(f'{uid}/speech_profile.wav') - if not blob.exists(): + try: + if not blob.exists(): + return False + except Forbidden: return False + # Check age if max_age_days is specified if max_age_days is not None: blob.reload() From e0ac4bcc74b9f9bceba3f038a1ad86d1a96076aa Mon Sep 17 00:00:00 2001 From: Neo <54811660+neooriginal@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:19:56 +0100 Subject: [PATCH 2/2] Update storage.py --- backend/utils/other/storage.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/utils/other/storage.py b/backend/utils/other/storage.py index a5d3c3ddb0..a4e8c43a9f 100644 --- a/backend/utils/other/storage.py +++ b/backend/utils/other/storage.py @@ -49,24 +49,25 @@ def upload_profile_audio(file_path: str, uid: str): def get_user_has_speech_profile(uid: str, max_age_days: int = None) -> bool: if not speech_profiles_bucket: return False - bucket = storage_client.bucket(speech_profiles_bucket) - blob = bucket.blob(f'{uid}/speech_profile.wav') + try: + bucket = storage_client.bucket(speech_profiles_bucket) + blob = bucket.blob(f'{uid}/speech_profile.wav') + if not blob.exists(): return False - except Forbidden: - return False - - # Check age if max_age_days is specified - if max_age_days is not None: - blob.reload() - if blob.time_created: - age = datetime.datetime.now(datetime.timezone.utc) - blob.time_created - if age.days > max_age_days: - return False + # Check age if max_age_days is specified + if max_age_days is not None: + blob.reload() + if blob.time_created: + age = datetime.datetime.now(datetime.timezone.utc) - blob.time_created + if age.days > max_age_days: + return False - return True + return True + except Forbidden: + return False def get_profile_audio_if_exists(uid: str, download: bool = True) -> str: