fix: update variable fields (#4022)
This commit is contained in:
parent
b10708194b
commit
e07892a88e
2 changed files with 10 additions and 5 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -155,11 +155,12 @@ def test_update_variable__ValueError(service, session):
|
|||
|
||||
def test_update_variable_fields(service, session):
|
||||
user_id = uuid4()
|
||||
new_name = new_value = "donkey"
|
||||
variable = service.create_variable(user_id, "old_name", "old_value", session=session)
|
||||
saved = variable.model_dump()
|
||||
variable = VariableUpdate(**saved)
|
||||
variable.name = "new_name"
|
||||
variable.value = "new_value"
|
||||
variable.name = new_name
|
||||
variable.value = new_value
|
||||
variable.default_fields = ["new_field"]
|
||||
|
||||
result = service.update_variable_fields(
|
||||
|
|
@ -169,6 +170,8 @@ def test_update_variable_fields(service, session):
|
|||
session=session,
|
||||
)
|
||||
|
||||
assert result.name == new_name
|
||||
assert result.value != new_value
|
||||
assert saved.get("id") == result.id
|
||||
assert saved.get("user_id") == result.user_id
|
||||
assert saved.get("name") != result.name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue