fix: Correctly handle query result rows when generating new trading plan ID

This commit is contained in:
Bobby (aider) 2025-02-11 18:17:33 -08:00
parent 0ac499ae8c
commit d17dc47d42

View File

@ -137,7 +137,8 @@ def save_trading_plan(plan: TradingPlan) -> int:
if not plan.id: if not plan.id:
# Generate new ID for new plans # Generate new ID for new plans
result = client.query("SELECT max(id) FROM trading_plans") result = client.query("SELECT max(id) FROM trading_plans")
plan.id = (result[0][0] or 0) + 1 max_id = result.result_rows[0][0] if result.result_rows else 0
plan.id = (max_id or 0) + 1
plan.created_at = datetime.now() plan.created_at = datetime.now()
plan.updated_at = datetime.now() plan.updated_at = datetime.now()