Fix additional nested session deadlock in data_processor.py

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 <noreply@anthropic.com>
This commit is contained in:
Urtzi Alfaro
2025-11-05 16:39:05 +01:00
parent e585e9fac0
commit b2de56ead3

View File

@@ -148,6 +148,11 @@ class EnhancedBakeryDataProcessor:
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)