From 67a34ffcb8bfae4ece853087e6ce62b93de30dce Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 27 Jun 2024 14:36:02 -0300 Subject: [PATCH] Refactor: handle error when retrieving messages from monitor service This commit refactors the code in the `migrate_messages_from_monitor_service_to_database` function to handle errors that may occur when retrieving messages from the monitor service. If an exception is raised, the error is logged and the function returns `False`. This ensures that the migration process can continue even if there is an issue with retrieving the messages. --- src/backend/base/langflow/services/database/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/services/database/utils.py b/src/backend/base/langflow/services/database/utils.py index fa40c725f..9500bcc50 100644 --- a/src/backend/base/langflow/services/database/utils.py +++ b/src/backend/base/langflow/services/database/utils.py @@ -18,8 +18,12 @@ def migrate_messages_from_monitor_service_to_database(session: Session) -> bool: from langflow.schema.message import Message from langflow.services.database.models.message import MessageTable - monitor_service = get_monitor_service() - messages_df = monitor_service.get_messages() + try: + monitor_service = get_monitor_service() + messages_df = monitor_service.get_messages() + except Exception as e: + logger.error(f"Error retrieving messages from monitor service: {e}") + return False if messages_df.empty: logger.info("No messages to migrate.")