From 04990a888beafbf9066afe81385928fe5c465ad6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 6 Apr 2026 09:26:08 +0200 Subject: [PATCH] fix: improve bot cleanup methods for safer shutdown --- freqtrade/freqtradebot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 2b4d6c8ff..24c45d048 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -216,7 +216,8 @@ class FreqtradeBot(LoggingMixin): logger.warning(f"Exception during cleanup: {e.__class__.__name__} {e}") finally: - self.strategy.ft_bot_cleanup() + if getattr(self, "strategy", None): + self.strategy.ft_bot_cleanup() if getattr(self, "rpc", None): self.rpc.cleanup() @@ -225,7 +226,8 @@ class FreqtradeBot(LoggingMixin): if getattr(self, "exchange", None): self.exchange.close() try: - Trade.commit() + if hasattr(Trade, "session"): + Trade.commit() except Exception: # Exceptions here will be happening if the db disappeared. # At which point we can no longer commit anyway.