From 55850a5ccde6594669e976c5dedf9f35e3050cdb Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 4 Feb 2023 08:39:01 +0100 Subject: [PATCH] Skip orders when correlated trade was deleted. closes #8107 --- freqtrade/freqtradebot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 8d12dd99f..0f10effc2 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -344,7 +344,15 @@ class FreqtradeBot(LoggingMixin): try: fo = self.exchange.fetch_order_or_stoploss_order(order.order_id, order.ft_pair, order.ft_order_side == 'stoploss') - + if not order.trade: + # This should not happen, but it does if trades were deleted manually. + # This can only incur on sqlite, which doesn't enforce foreign constraints. + logger.warning( + f"Order {order.order_id} has no trade attached. " + "This may suggest a database corruption. " + f"The expected trade ID is {order.ft_trade_id}. Ignoring this order." + ) + continue self.update_trade_state(order.trade, order.order_id, fo, stoploss_order=(order.ft_order_side == 'stoploss'))