From 68d9f241e137c6b7dcfe70db768186229683dfe3 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 2 Nov 2025 15:24:29 -0500 Subject: [PATCH] fix: use closure to capture db_path in lifespan context manager - Fix lifespan function to access db_path from create_app scope via closure - Prevents "no such table: jobs" error by ensuring database initialization runs - Previous version tried to access app.state.db_path before it was set The issue was that app.state is set after FastAPI instantiation, but the lifespan function needs the db_path during startup. Using closure allows the lifespan function to capture db_path from the create_app function scope. --- api/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/main.py b/api/main.py index 1cc784f..39d5c24 100644 --- a/api/main.py +++ b/api/main.py @@ -134,15 +134,15 @@ def create_app( from tools.deployment_config import is_dev_mode, get_db_path from api.database import initialize_dev_database, initialize_database - # Startup + # Startup - use closure to access db_path from create_app scope if is_dev_mode(): # Initialize dev database (reset unless PRESERVE_DEV_DATA=true) - dev_db_path = get_db_path(app.state.db_path) + dev_db_path = get_db_path(db_path) initialize_dev_database(dev_db_path) log_dev_mode_startup_warning() else: # Ensure production database schema exists - initialize_database(app.state.db_path) + initialize_database(db_path) yield