diff --git a/services/training/app/ml/prophet_manager.py b/services/training/app/ml/prophet_manager.py index ebab84e7..aa6dcbd2 100644 --- a/services/training/app/ml/prophet_manager.py +++ b/services/training/app/ml/prophet_manager.py @@ -801,14 +801,11 @@ class BakeryProphetManager: db_model.data_quality_score = float(training_metrics.get('data_quality_score')) if training_metrics.get('data_quality_score') is not None else None db_session.add(db_model) - - # Only commit if using a new session, not if using parent session - # Parent session commits will be handled by the calling method to prevent conflicts - if not use_parent_session: - await db_session.commit() - logger.info(f"Model {model_id} stored in database successfully") - else: - logger.debug(f"Added model {model_id} to parent session (commit deferred)") + + # ✅ FIX: Don't commit here - let the outer scope handle commits + # This prevents double commit when using a new dedicated session + # Parent sessions will commit when parent completes; new sessions commit in outer scope + logger.debug(f"Added model {model_id} to session (commit handled by caller)") try: # ✅ FIX: Use parent session if provided, otherwise create new one @@ -977,9 +974,8 @@ class BakeryProphetManager: holidays_df = holidays_df.drop_duplicates(subset=['ds', 'holiday']) holidays_df = holidays_df.sort_values('ds').reset_index(drop=True) - logger.info(f"Loaded {len(holidays_df)} Spanish holidays dynamically", - region=region or 'National', - years=f"{min(years)}-{max(years)}") + # ✅ FIX: Don't pass keyword args to logger - use f-string instead + logger.info(f"Loaded {len(holidays_df)} Spanish holidays dynamically (region={region or 'National'}, years={min(years)}-{max(years)})") return holidays_df else: