fix(ai-ops): HealLog DetachedInstanceError — refresh before expunge
All checks were successful
CD Pipeline / deploy (push) Successful in 1m21s

SQLAlchemy expire_on_commit=True(預設) 會在 commit 後清空 ORM 屬性。
expunge 單獨使用仍會觸發 lazy-load → DetachedInstanceError。
修正:commit → refresh(重載屬性入記憶體)→ expunge(脫離 session)。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-19 16:14:00 +08:00
parent cb03f6b3e8
commit 352a99db58

View File

@@ -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()