From 90b6ad400d69ac52e3d8b54887c1bfd305ae38d9 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 2 Nov 2025 15:52:25 -0500 Subject: [PATCH] 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 --- tools/deployment_config.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/deployment_config.py b/tools/deployment_config.py index 79dd66f..434dffd 100644 --- a/tools/deployment_config.py +++ b/tools/deployment_config.py @@ -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"