OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
Move Langflow settings sync to background.
Olfa Maslah8a6431a12f73
diff --git a/src/api/settings.py b/src/api/settings.pyindex 0fec0a2ec..b843518d6 100644--- a/src/api/settings.py+++ b/src/api/settings.py@@ -1,3 +1,4 @@+import asyncioimport jsonimport platformfrom fastapi import Depends, Request, HTTPException@@ -830,30 +831,27 @@ async def update_settings({"error": "Failed to save configuration"}, status_code=500)- # Update Langflow global variables and model values if provider settings changed+ # Refresh patched client immediately so subsequent requests pick up latest config.await clients.refresh_patched_client()+ # Run expensive Langflow sync in the background to keep settings updates responsive.if should_validate or provider_updated:- try:- flows_service = _get_flows_service()-- # Update global variables- await _update_langflow_global_variables(current_config, flows_service=flows_service)-- # Update LLM client credentials when embedding selection changes- if body.embedding_provider is not None or body.embedding_model is not None:- await _update_mcp_servers_with_provider_credentials(- current_config, session_manager, flows_service=flows_service- )-- # Update model values if provider or model changed (including removals that trigger fallback)- if body.llm_provider is not None or body.llm_model is not None or body.embedding_provider is not None or body.embedding_model is not None or provider_updated:- await _update_langflow_model_values(current_config, flows_service)-- except Exception as e:- logger.error(f"Failed to update Langflow settings: {str(e)}")- # Don't fail the entire settings update if Langflow update fails- # The config was still saved+ asyncio.create_task(+ _run_async_post_save_langflow_updates(+ session_manager=session_manager,+ update_mcp_servers=(+ body.embedding_provider is not None+ or body.embedding_model is not None+ ),+ update_model_values=(+ body.llm_provider is not None+ or body.llm_model is not None+ or body.embedding_provider is not None+ or body.embedding_model is not None+ or provider_updated+ ),+ )+ )set_fields = [k for k, v in body.model_dump().items() if v is not None]@@ -1402,6 +1400,37 @@ async def _update_langflow_global_variables(config, flows_service=None):raise+async def _run_async_post_save_langflow_updates(+ session_manager,+ update_mcp_servers: bool,+ update_model_values: bool,+) -> None:+ """Apply post-save Langflow synchronization asynchronously."""+ try:+ current_config = get_openrag_config()+ flows_service = _get_flows_service()++ # Update global variables+ await _update_langflow_global_variables(+ current_config, flows_service=flows_service+ )++ # Update LLM client credentials when embedding selection changes+ if update_mcp_servers:+ await _update_mcp_servers_with_provider_credentials(+ current_config, session_manager, flows_service=flows_service+ )++ # Update model values if provider/model changed (including removals/fallbacks)+ if update_model_values:+ await _update_langflow_model_values(current_config, flows_service)++ logger.info("Completed asynchronous Langflow post-save sync")+ except Exception as e:+ # Do not fail user request if async sync fails; keep parity with existing behavior.+ logger.error(f"Failed to update Langflow settings asynchronously: {str(e)}")++async def _update_mcp_servers_with_provider_credentials(config, session_manager = None, flows_service=None):# Update MCP servers with provider credentialstry: