Skip to content

~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.

Revert "Revert "fix(settings): handle unchecked checkboxes in settings forms""

LearningCircuit462078a99482
diff --git a/src/local_deep_research/__version__.py b/src/local_deep_research/__version__.py
index 64c7d51e0c..b7e1990493 100644
--- a/src/local_deep_research/__version__.py
+++ b/src/local_deep_research/__version__.py
@@ -1 +1 @@
-__version__ = "1.2.6"
+__version__ = "1.2.5"
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index 50cdb2c4ee..1ae267080a 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -49,6 +49,61 @@ def _get_setting_from_session(key: str, default=None):
return default
+def normalize_checkbox_form_data(all_settings, form_data):
+ """
+ Normalize checkbox form data to handle HTML form behavior where unchecked checkboxes
+ are not included in form submission.
+
+ Args:
+ all_settings: Dictionary of all settings from settings manager
+ form_data: Dictionary of form data from request
+
+ Returns:
+ Updated form_data dictionary with normalized checkbox values
+ """
+ # Handle error cases
+ if all_settings is None:
+ logger.warning("all_settings is None in normalize_checkbox_form_data")
+ return form_data
+
+ if not isinstance(all_settings, dict):
+ logger.warning(
+ f"all_settings has unexpected type: {type(all_settings)}"
+ )
+ return form_data
+
+ if form_data is None:
+ logger.warning("form_data is None in normalize_checkbox_form_data")
+ return {}
+
+ if not isinstance(form_data, dict):
+ logger.warning(f"form_data has unexpected type: {type(form_data)}")
+ return {}
+
+ try:
+ # Handle all checkboxes consistently
+ for key, setting_data in all_settings.items():
+ if not isinstance(setting_data, dict):
+ logger.warning(
+ f"Setting data for key '{key}' is not a dict: {type(setting_data)}"
+ )
+ continue
+
+ if setting_data.get("ui_element") == "checkbox":
+ if key not in form_data:
+ # Checkbox was not in form data (unchecked), set to False
+ form_data[key] = False
+ else:
+ # Checkbox was in form data, convert to boolean
+ form_data[key] = form_data[key] == "on"
+ except Exception:
+ logger.exception("Error in normalize_checkbox_form_data")
+ # Return the original form_data if processing fails
+ return form_data
+
+ return form_data
+
+
def calculate_warnings():
"""Calculate current warning conditions based on settings"""
warnings = []
@@ -197,17 +252,30 @@ def save_all_settings():
# get_db_settings_manager(db_session)
try:
- # Process JSON data
+ # Try to process JSON data first (expected from JavaScript)
form_data = request.get_json()
+
+ # If no JSON data, fall back to form data (traditional form submission)
if not form_data:
- return (
- jsonify(
- {
- "status": "error",
- "message": "No settings data provided",
- }
- ),
- 400,
+ logger.info("No JSON data received, falling back to form data")
+ form_data = request.form.to_dict()
+ # Remove CSRF token from the data
+ form_data.pop("csrf_token", None)
+
+ # Handle checkbox settings specifically for traditional form submission
+ # When unchecked, they won't be in form_data, so we need to explicitly set them to False
+ settings_manager = SettingsManager(db_session)
+
+ # Get all settings
+ all_settings = settings_manager.get_all_settings()
+
+ # Normalize checkbox form data using shared helper
+ form_data = normalize_checkbox_form_data(
+ all_settings, form_data
+ )
+
+ logger.info(
+ f"Processed form data with {len(form_data)} settings"
)
# Track validation errors
@@ -306,6 +374,11 @@ def save_all_settings():
pass
if current_setting:
+ # Check if setting is editable before attempting to save
+ if not current_setting.editable:
+ logger.warning(f"Skipping non-editable setting: {key}")
+ continue
+
# Validate the setting
is_valid, error_message = validate_setting(
current_setting, value
@@ -477,6 +550,11 @@ def save_all_settings():
f"Bulk settings update affected warning keys, calculated {len(warnings)} warnings"
)
+ # Sync server config with updated settings
+ settings_manager = SettingsManager(db_session)
+ settings_snapshot = settings_manager.get_settings_snapshot()
+ sync_from_settings(settings_snapshot)
+
return jsonify(response_data)
except Exception:
@@ -541,15 +619,18 @@ def save_settings():
updated_count = 0
failed_count = 0
+ # Handle checkbox settings specifically
+ # When unchecked, they won't be in form_data, so we need to explicitly set them to False
+
+ # Get all settings
+ all_settings = settings_manager.get_all_settings()
+
+ # Normalize checkbox form data using shared helper
+ form_data = normalize_checkbox_form_data(all_settings, form_data)
+
# Process each setting
for key, value in form_data.items():
try:
- # Handle checkbox values
- if value == "on":
- value = True
- elif value == "off" or value == "":
- value = False
-
# Try to convert numeric values
if (
isinstance(value, str)
@@ -563,6 +644,16 @@ def save_settings():
except ValueError:
pass # Keep as string
+ # Check if setting is editable before attempting to save
+ current_setting = (
+ db_session.query(Setting)
+ .filter(Setting.key == key)
+ .first()
+ )
+ if current_setting and not current_setting.editable:
+ logger.warning(f"Skipping non-editable setting: {key}")
+ continue
+
# Save the setting
if settings_manager.set_setting(key, value, commit=False):
updated_count += 1
@@ -1868,6 +1959,8 @@ def fix_corrupted_settings():
default_value = 5000
elif setting.key == "app.debug":
default_value = True
+ elif setting.key == "app.allow_registrations":
+ default_value = True
# Update the setting with the default value if found
if default_value is not None:
diff --git a/src/local_deep_research/web/static/js/components/settings.js b/src/local_deep_research/web/static/js/components/settings.js
index 5448e84310..5ccf0c5b9d 100644
--- a/src/local_deep_research/web/static/js/components/settings.js
+++ b/src/local_deep_research/web/static/js/components/settings.js
@@ -1131,13 +1131,14 @@
'dark_mode',
'default_theme',
'theme',
- 'warnings'
+ 'warnings',
+ 'allow_registrations'
]
};
// Priority settings that should appear at the top of each tab
const prioritySettings = {
- 'app': ['enable_web', 'enable_notifications', 'web_interface', 'theme', 'default_theme', 'dark_mode', 'debug', 'host', 'port', 'warnings'],
+ 'app': ['enable_web', 'enable_notifications', 'web_interface', 'theme', 'default_theme', 'dark_mode', 'debug', 'host', 'port', 'warnings', 'allow_registrations'],
'llm': ['provider', 'model', 'temperature', 'max_tokens', 'api_key', 'openai_endpoint_url', 'lmstudio_url', 'llamacpp_model_path'],
'search': ['tool', 'iterations', 'questions_per_iteration', 'max_results', 'region', 'search_engine'],
'report': ['enable_fact_checking', 'knowledge_accumulation', 'output_dir', 'detailed_citations']