From c4cb7607eef66a9ef14d003f59cc152fb3f2c0f4 Mon Sep 17 00:00:00 2001 From: Michael Wallace Date: Wed, 4 Feb 2026 12:37:06 +0000 Subject: [PATCH] fix: Apply env var fallback fix to lfx module (#11584) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applies the fix from PR #9422 (commit 18e2ff2d2d) to the lfx module, which was previously only applied to the backend module. PR #9422 fixed a bug where environment variable fallback would fail when `load_from_db=True` inputs couldn't find variables in the database. The fix properly distinguishes between two error cases: - "User id is not set" → always raise (authentication issue) - "variable not found." → only raise if fallback_to_env_vars=False However, this fix was only applied to: - src/backend/base/langflow/interface/initialize/loading.py And was missing from: - src/lfx/src/lfx/interface/initialize/loading.py PR #9902 added table field support and reorganized the test imports to use the lfx module (which has table support). The test was updated to use "Database connection failed" error message to work with the existing code, rather than "variable not found." which would trigger the bug. This commit: 1. Applies the bug fix to the lfx module's regular field handler 2. Restores the original test behavior using "variable not found." to properly validate that the fix works - src/lfx/src/lfx/interface/initialize/loading.py Fixed error handling to respect fallback_to_env_vars flag - src/backend/tests/unit/interface/initialize/test_loading.py Restored "variable not found." error to properly validate the fix Fixes: https://github.com/langflow-ai/langflow/issues/11422 Related: #9422, #9902 --- .../tests/unit/interface/initialize/test_loading.py | 8 +++++--- src/lfx/src/lfx/interface/initialize/loading.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/backend/tests/unit/interface/initialize/test_loading.py b/src/backend/tests/unit/interface/initialize/test_loading.py index 283109f7b1..106632fa88 100644 --- a/src/backend/tests/unit/interface/initialize/test_loading.py +++ b/src/backend/tests/unit/interface/initialize/test_loading.py @@ -12,15 +12,17 @@ from lfx.interface.initialize.loading import ( async def test_update_params_fallback_to_env_when_variable_not_found(): """Test that when a variable is not found in database and fallback_to_env_vars is True. - It falls back to environment variables. + It falls back to environment variables. This specifically tests the fix for the bug + where 'variable not found.' error would always raise, even with fallback enabled. """ # Set up environment variable os.environ["TEST_API_KEY"] = "test-secret-key-123" # Create mock custom component custom_component = MagicMock() - # Change this error message to avoid triggering re-raise - custom_component.get_variable = AsyncMock(side_effect=ValueError("Database connection failed")) + # Use "variable not found." error to specifically test the fix + # Previously this would always raise, even with fallback_to_env_vars=True + custom_component.get_variable = AsyncMock(side_effect=ValueError("TEST_API_KEY variable not found.")) # Set up params with a field that should load from db params = {"api_key": "TEST_API_KEY"} diff --git a/src/lfx/src/lfx/interface/initialize/loading.py b/src/lfx/src/lfx/interface/initialize/loading.py index 229066a00f..7191788c16 100644 --- a/src/lfx/src/lfx/interface/initialize/loading.py +++ b/src/lfx/src/lfx/interface/initialize/loading.py @@ -271,7 +271,9 @@ async def update_params_with_load_from_db_fields( try: key = await custom_component.get_variable(name=params[field], field=field, session=session) except ValueError as e: - if any(reason in str(e) for reason in ["User id is not set", "variable not found."]): + if "User id is not set" in str(e): + raise + if "variable not found." in str(e) and not fallback_to_env_vars: raise logger.debug(str(e)) key = None