From 35acae06c7f3f7aef1d28aa55fb8b1fdd85f8a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vit=C3=B3ria=20Silva?= Date: Fri, 14 Nov 2025 22:47:55 +0000 Subject: [PATCH] Improve activity filtering Filters out None values from the activities list and returns None if the list is empty #395 --- backend/app/activities/activity/router.py | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/app/activities/activity/router.py b/backend/app/activities/activity/router.py index ed2f9c0bb..7abed423b 100644 --- a/backend/app/activities/activity/router.py +++ b/backend/app/activities/activity/router.py @@ -521,12 +521,11 @@ async def read_activities_user_activities_refresh( if garmin_activities is not None: activities.extend(garmin_activities) - # Check if activities is None and return None if it is - if activities is None: - return None + # Filter out None values from the activities list + activities = [activity for activity in activities if activity is not None] - # Return the activities - return activities + # Return the activities or None if the list is empty + return activities if activities else None @router.get( @@ -654,13 +653,17 @@ async def create_activity_with_bulk_import( # Check if file is one we can process _, file_extension = os.path.splitext(file_path) if file_extension not in supported_file_formats: - core_logger.print_to_log_and_console(f"Skipping file {file_path} due to not having a supported file extension. Supported extensions are: {supported_file_formats}.") + core_logger.print_to_log_and_console( + f"Skipping file {file_path} due to not having a supported file extension. Supported extensions are: {supported_file_formats}." + ) # Might be good to notify the user, but background tasks cannot raise HTTPExceptions continue if os.path.isfile(file_path): # Log the file being processed - core_logger.print_to_log_and_console(f"Queuing file for processing: {file_path}") + core_logger.print_to_log_and_console( + f"Queuing file for processing: {file_path}" + ) # Parse and store the activity background_tasks.add_task( activities_utils.parse_and_store_activity_from_file, @@ -671,10 +674,14 @@ async def create_activity_with_bulk_import( ) # Log a success message that explains processing will continue elsewhere. - core_logger.print_to_log_and_console("Bulk import initiated for all files found in the bulk_import directory. Processing of files will continue in the background.") + core_logger.print_to_log_and_console( + "Bulk import initiated for all files found in the bulk_import directory. Processing of files will continue in the background." + ) # Return a success message - return {"Bulk import initiated for all files found in the bulk_import directory. Processing of files will continue in the background."} + return { + "Bulk import initiated for all files found in the bulk_import directory. Processing of files will continue in the background." + } except Exception as err: # Log the exception core_logger.print_to_log(