Skip to content

Commit

Permalink
fix: Improve variable decryption error handling (#6199)
Browse files Browse the repository at this point in the history
* fix: Improve variable decryption error handling in DatabaseVariableService

Add robust error handling for variable decryption, logging decryption failures and falling back to the original value for generic type variables

* chore: Bump version to 1.1.4.post1 for langflow and 0.1.4.post1 for langflow-base
  • Loading branch information
ogabrielluiz authored Feb 7, 2025
1 parent 141e673 commit f9b2ce1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[project]
name = "langflow"
version = "1.1.4"
version = "1.1.4.post1"
description = "A Python package with a built-in web application"
requires-python = ">=3.10,<3.13"
license = "MIT"
Expand All @@ -19,7 +19,7 @@ maintainers = [
]
# Define your main dependencies here
dependencies = [
"langflow-base==0.1.4",
"langflow-base==0.1.4.post1",
"beautifulsoup4==4.12.3",
"google-search-results>=2.4.1,<3.0.0",
"google-api-python-client==2.154.0",
Expand Down
12 changes: 9 additions & 3 deletions src/backend/base/langflow/services/variable/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ async def get_variable(
async def get_all(self, user_id: UUID | str, session: AsyncSession) -> list[VariableRead]:
stmt = select(Variable).where(Variable.user_id == user_id)
variables = list((await session.exec(stmt)).all())
# If the variable is of type 'Generic' we decrypt the value
# For variables of type 'Generic', attempt to decrypt the value.
# If decryption fails, assume the value is already plaintext.
variables_read = []
for variable in variables:
value = None
if variable.type == GENERIC_TYPE:
value = auth_utils.decrypt_api_key(variable.value, settings_service=self.settings_service)

try:
value = auth_utils.decrypt_api_key(variable.value, settings_service=self.settings_service)
except Exception as e: # noqa: BLE001
logger.debug(
f"Decryption of {variable.type} failed for variable '{variable.name}': {e}. Assuming plaintext."
)
value = variable.value
variable_read = VariableRead.model_validate(variable, from_attributes=True)
variable_read.value = value
variables_read.append(variable_read)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "langflow-base"
version = "0.1.4"
version = "0.1.4.post1"
description = "A Python package with a built-in web application"
requires-python = ">=3.10,<3.13"
license = "MIT"
Expand Down
44 changes: 20 additions & 24 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9b2ce1

Please sign in to comment.