From b2de56ead3ebd5fe80fef264ad53496b18c009f2 Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Wed, 5 Nov 2025 16:39:05 +0100 Subject: [PATCH] Fix additional nested session deadlock in data_processor.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root Cause: After fixing the training_service.py deadlock, training progressed to data preparation but got stuck there. The data_processor.py creates another nested session at line 143, updates training_log without committing, causing another deadlock scenario. Session Hierarchy: 1. training_service.py: outer session (fixed in e585e9f) 2. trainer.py: creates own session (passes deadlock due to commit) 3. data_processor.py: creates ANOTHER nested session (THIS FIX) Fix: Added explicit db_session.commit() after progress update in data_processor (line 153) to ensure the UPDATE is committed before continuing with data processing operations that may interact with other sessions. This completes the chain of nested session fixes: - caff497: prophet_manager + hybrid_trainer session passing - e585e9f: training_service commit before trainer call - THIS: data_processor commit after progress update 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- services/training/app/ml/data_processor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/training/app/ml/data_processor.py b/services/training/app/ml/data_processor.py index 8f4fc7ed..94968418 100644 --- a/services/training/app/ml/data_processor.py +++ b/services/training/app/ml/data_processor.py @@ -142,13 +142,18 @@ class EnhancedBakeryDataProcessor: # Get database session and repositories async with self.database_manager.get_session() as db_session: repos = await self._get_repositories(db_session) - + # Log data preparation start if we have tracking info if job_id and tenant_id: await repos['training_log'].update_log_progress( job_id, 15, f"preparing_data_{inventory_product_id}", "running" ) - + # ✅ FIX: Commit the session to prevent deadlock with parent trainer session + # The trainer has its own session, so we need to commit this update + await db_session.commit() + logger.debug("Committed session after data preparation progress update", + inventory_product_id=inventory_product_id) + # Step 1: Convert and validate sales data sales_clean = await self._process_sales_data(sales_data, inventory_product_id)