fix: Improve variable decryption error handling (#6199)

* 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
This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-02-07 15:34:13 -03:00 committed by GitHub
commit f9b2ce18a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 30 deletions

View file

@ -83,13 +83,19 @@ class DatabaseVariableService(VariableService, Service):
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)

View file

@ -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"