From a20439bf8122315c59ceb533ba39c01dc3e1e1c4 Mon Sep 17 00:00:00 2001 From: caiming100 <365215504@qq.com> Date: Tue, 8 Apr 2025 16:06:57 +0800 Subject: [PATCH] fix: add exception handling for get_by_id method (#6861) ### What problem does this PR solve? Fixes #6548 Add exception handling to prevent exceptions from propagating back to the web, which may lead to failure in displaying conversation content. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): Co-authored-by: cm --- api/db/services/common_service.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/db/services/common_service.py b/api/db/services/common_service.py index 75bc1a6f..cf31a2a6 100644 --- a/api/db/services/common_service.py +++ b/api/db/services/common_service.py @@ -225,9 +225,12 @@ class CommonService: # pid: Record ID # Returns: # Tuple of (success, record) - obj = cls.model.get_or_none(cls.model.id == pid) - if obj: - return True, obj + try: + obj = cls.model.get_or_none(cls.model.id == pid) + if obj: + return True, obj + except Exception: + pass return False, None @classmethod