fix: update variable fields (#4022)

This commit is contained in:
Ítalo Johnny 2024-10-04 16:49:36 -03:00 • committed by GitHub
commit e07892a88e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -127,13 +127,15 @@ class DatabaseVariableService(VariableService, Service):
):
query = select(Variable).where(Variable.id == variable_id, Variable.user_id == user_id)
db_variable = session.exec(query).one()
db_variable.updated_at = datetime.now(timezone.utc)
variable.value = variable.value or ""
encrypted = auth_utils.encrypt_api_key(variable.value, settings_service=self.settings_service)
variable.value = encrypted
variable_data = variable.model_dump(exclude_unset=True)
for key, value in variable_data.items():
setattr(db_variable, key, value)
db_variable.updated_at = datetime.now(timezone.utc)
encrypted = auth_utils.encrypt_api_key(db_variable.value, settings_service=self.settings_service)
variable.value = encrypted
session.add(db_variable)
session.commit()