mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
fix: make get_db_path() idempotent to prevent recursive _dev suffix
Root Cause: The get_db_path() function was being called multiple times in the initialization chain, causing recursive suffix addition: data/jobs.db -> data/jobs_dev.db -> data/jobs_dev_dev.db This resulted in tables being created in data/jobs_dev_dev.db while the application tried to access data/jobs_dev.db (empty database). Fix: Added idempotency check in get_db_path() to detect and skip transformation if path already contains "_dev.db" suffix. Evidence from Diagnostics: - alpha.20 logs showed: Input='data/jobs_dev.db', Resolved='data/jobs_dev_dev.db' - Tables were created in jobs_dev_dev.db but accessed from jobs_dev.db - This caused "no such table: jobs" errors despite successful initialization All 28 integration tests pass with this fix. Fixes #6
This commit is contained in:
@@ -69,8 +69,16 @@ def get_db_path(base_db_path: str) -> str:
|
||||
Example:
|
||||
PROD: "data/trading.db" -> "data/trading.db"
|
||||
DEV: "data/trading.db" -> "data/trading_dev.db"
|
||||
|
||||
Note:
|
||||
This function is idempotent - calling it multiple times on the same
|
||||
path will not add multiple _dev suffixes.
|
||||
"""
|
||||
if is_dev_mode():
|
||||
# Check if already has _dev suffix (idempotent)
|
||||
if "_dev.db" in base_db_path:
|
||||
return base_db_path
|
||||
|
||||
# Insert _dev before .db extension
|
||||
if base_db_path.endswith(".db"):
|
||||
return base_db_path[:-3] + "_dev.db"
|
||||
|
||||
Reference in New Issue
Block a user