fix: avoid AttributeError when password is not provided in compute update

When updating a compute without providing a password field,
compute_update.password is None and calling .get_secret_value()
on it causes a 500 Internal Server Error. Only set the password
in update_values when a password is actually provided.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
YueGuobin 2026-04-30 09:38:55 +08:00
parent f0ef65b8e8
commit a6dcab8110
No known key found for this signature in database

View File

@ -69,7 +69,8 @@ class ComputesRepository(BaseRepository):
async def update_compute(self, compute_id: UUID, compute_update: schemas.ComputeUpdate) -> Optional[models.Compute]:
update_values = compute_update.model_dump(exclude_unset=True)
update_values["password"] = compute_update.password.get_secret_value()
if compute_update.password is not None:
update_values["password"] = compute_update.password.get_secret_value()
query = update(models.Compute).\
where(models.Compute.compute_id == compute_id).\