From fadc9036a2e4edea4b8412092283815efcd2b707 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Fri, 19 Dec 2025 21:54:11 +0100 Subject: [PATCH] fix: add db.rollback() to prevent session state corruption during historical import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When create_letzshop_order raises an exception (e.g., product not found by GTIN) after flushing the order to the database, the session is left in an inconsistent state. Without rollback, subsequent database operations fail or hang, causing the import to get stuck at "0 processed...". 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app/services/letzshop/order_service.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/services/letzshop/order_service.py b/app/services/letzshop/order_service.py index 2b98a294..11929600 100644 --- a/app/services/letzshop/order_service.py +++ b/app/services/letzshop/order_service.py @@ -711,6 +711,10 @@ class LetzshopOrderService: self.create_order(vendor_id, shipment) stats["imported"] += 1 except Exception as e: + # Rollback session to clear any partial changes from failed order + # This is crucial because create_letzshop_order may have flushed + # the order before the exception was raised (e.g., product not found) + self.db.rollback() stats["errors"] += 1 stats["error_messages"].append( f"Shipment {shipment_id}: {str(e)}"