~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(tests): add try/finally guards for sqlite3 and session cleanup (#3215)
LearningCircuit96985ed34e92
diff --git a/tests/api_tests/migrate_research_mode.py b/tests/api_tests/migrate_research_mode.pyindex 0f1cfd07fb..39a4c03b75 100644--- a/tests/api_tests/migrate_research_mode.py+++ b/tests/api_tests/migrate_research_mode.py@@ -21,6 +21,10 @@ def add_research_mode_column(db_path: str):"""Add research_mode column to tables if it doesn't exist."""try:conn = sqlite3.connect(db_path)+ except Exception:+ logger.exception(f"Error connecting to {db_path}")+ return+ try:cursor = conn.cursor()# Check if column exists in token_usage@@ -57,11 +61,11 @@ def add_research_mode_column(db_path: str):f"research_mode column already exists in search_calls in {db_path}")- conn.close()logger.info(f"Successfully updated {db_path}")-except Exception:logger.exception(f"Error updating {db_path}")+ finally:+ conn.close()def migrate_all_user_databases():diff --git a/tests/test_settings_manager.py b/tests/test_settings_manager.pyindex 7598ca9382..51823130cd 100644--- a/tests/test_settings_manager.py+++ b/tests/test_settings_manager.py@@ -225,31 +225,32 @@ def test_app_get_setting_from_real_db(SessionLocal = setup_database_for_all_tests # Get the SessionLocal class from the fixturesession = SessionLocal() # Create a new session instance for this test- # Add a setting to the database using this session- # Changed key to be specific to this test- setting = Setting(- key="test.app.version.get", # Use a unique key for this test- value="1.0.0",- type=SettingType.APP,- name="Version",- description="App version",- ui_element="text",- visible=True,- editable=True,- )- session.add(setting)- session.commit()-- monkeypatch.delenv(- "LDR_APP_VERSION", raising=False- ) # Ensure no env override+ try:+ # Add a setting to the database using this session+ # Changed key to be specific to this test+ setting = Setting(+ key="test.app.version.get", # Use a unique key for this test+ value="1.0.0",+ type=SettingType.APP,+ name="Version",+ description="App version",+ ui_element="text",+ visible=True,+ editable=True,+ )+ session.add(setting)+ session.commit()- # Create settings manager with the session and get the setting- settings_manager = SettingsManager(db_session=session)- value = settings_manager.get_setting("test.app.version.get")- assert value == "1.0.0"+ monkeypatch.delenv(+ "LDR_APP_VERSION", raising=False+ ) # Ensure no env override- session.close() # Close the session for this test+ # Create settings manager with the session and get the setting+ settings_manager = SettingsManager(db_session=session)+ value = settings_manager.get_setting("test.app.version.get")+ assert value == "1.0.0"+ finally:+ session.close() # Close the session for this testdef test_get_all_settings_from_real_file_db(@@ -263,54 +264,58 @@ def test_get_all_settings_from_real_file_db(setup_database_for_all_tests()) # Call the sessionmaker to get a new session- # Add some settings to the database- setting1 = Setting(- key="all.settings.app.version",- value="1.0.0",- type=SettingType.APP,- name="Version",- description="App version",- ui_element="text",- visible=True,- editable=True,- )- setting2 = Setting(- key="all.settings.llm.temperature",- value=0.7,- type=SettingType.LLM,- name="Temperature",- description="LLM temperature",- ui_element="number",- visible=True,- editable=True,- )- session.add_all([setting1, setting2])- session.commit() # Commit to save them to the database-- # Ensure no conflicting environment variables are set for this test- monkeypatch.delenv("LDR_APP_VERSION", raising=False)- monkeypatch.delenv("LDR_LLM_TEMPERATURE", raising=False)-- settings_manager = SettingsManager(- db_session=session- ) # Pass the session instance- all_settings = settings_manager.get_all_settings()-- # Assertions should check for the unique keys- assert "all.settings.app.version" in all_settings- assert all_settings["all.settings.app.version"]["value"] == "1.0.0"- assert all_settings["all.settings.app.version"]["type"] == "APP"- assert all_settings["all.settings.app.version"]["editable"] is True- assert all_settings["all.settings.app.version"]["name"] == "Version"-- assert "all.settings.llm.temperature" in all_settings- assert all_settings["all.settings.llm.temperature"]["value"] == 0.7- assert all_settings["all.settings.llm.temperature"]["type"] == "LLM"- assert all_settings["all.settings.llm.temperature"]["editable"] is True- assert all_settings["all.settings.llm.temperature"]["name"] == "Temperature"-- # IMPORTANT: Close the session created within the test- session.close()+ try:+ # Add some settings to the database+ setting1 = Setting(+ key="all.settings.app.version",+ value="1.0.0",+ type=SettingType.APP,+ name="Version",+ description="App version",+ ui_element="text",+ visible=True,+ editable=True,+ )+ setting2 = Setting(+ key="all.settings.llm.temperature",+ value=0.7,+ type=SettingType.LLM,+ name="Temperature",+ description="LLM temperature",+ ui_element="number",+ visible=True,+ editable=True,+ )+ session.add_all([setting1, setting2])+ session.commit() # Commit to save them to the database++ # Ensure no conflicting environment variables are set for this test+ monkeypatch.delenv("LDR_APP_VERSION", raising=False)+ monkeypatch.delenv("LDR_LLM_TEMPERATURE", raising=False)++ settings_manager = SettingsManager(+ db_session=session+ ) # Pass the session instance+ all_settings = settings_manager.get_all_settings()++ # Assertions should check for the unique keys+ assert "all.settings.app.version" in all_settings+ assert all_settings["all.settings.app.version"]["value"] == "1.0.0"+ assert all_settings["all.settings.app.version"]["type"] == "APP"+ assert all_settings["all.settings.app.version"]["editable"] is True+ assert all_settings["all.settings.app.version"]["name"] == "Version"++ assert "all.settings.llm.temperature" in all_settings+ assert all_settings["all.settings.llm.temperature"]["value"] == 0.7+ assert all_settings["all.settings.llm.temperature"]["type"] == "LLM"+ assert all_settings["all.settings.llm.temperature"]["editable"] is True+ assert (+ all_settings["all.settings.llm.temperature"]["name"]+ == "Temperature"+ )+ finally:+ # IMPORTANT: Close the session created within the test+ session.close()def test_get_all_settings_db_error(mock_db_session, mock_logger):