From 352a99db58a93ac8ac19cc129af3b00f3bb01e1e Mon Sep 17 00:00:00 2001 From: ogt Date: Sun, 19 Apr 2026 16:14:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(ai-ops):=20HealLog=20DetachedInstanceError?= =?UTF-8?q?=20=E2=80=94=20refresh=20before=20expunge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SQLAlchemy expire_on_commit=True(預設) 會在 commit 後清空 ORM 屬性。 expunge 單獨使用仍會觸發 lazy-load → DetachedInstanceError。 修正:commit → refresh(重載屬性入記憶體)→ expunge(脫離 session)。 Co-Authored-By: Claude Sonnet 4.6 --- services/auto_heal_service.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/auto_heal_service.py b/services/auto_heal_service.py index 76a594e..1e23692 100644 --- a/services/auto_heal_service.py +++ b/services/auto_heal_service.py @@ -373,7 +373,8 @@ class AutoHealService: ) session.add(hl) session.commit() - session.expunge(hl) # detach after commit to keep loaded attrs + session.refresh(hl) # reload attrs into memory (expire_on_commit cleared them) + session.expunge(hl) # detach so attrs stay accessible after session.close() return hl except Exception as e: session.rollback()