From 42742d03d7689744f6f2e1bf901c66a6c84100f7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 8 Jul 2024 11:58:36 -0700 Subject: [PATCH] fix: model update --- backend/apps/webui/models/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/apps/webui/models/models.py b/backend/apps/webui/models/models.py index 0aeac3e24..300a805fe 100644 --- a/backend/apps/webui/models/models.py +++ b/backend/apps/webui/models/models.py @@ -159,11 +159,15 @@ class ModelsTable: def update_model_by_id(self, id: str, model: ModelForm) -> Optional[ModelModel]: try: with get_db() as db: - # update only the fields that are present in the model - model = db.query(Model).get(id) - model.update(**model.model_dump()) + result = ( + db.query(Model) + .filter_by(id=id) + .update(model.model_dump(exclude={"id"}, exclude_none=True)) + ) db.commit() + + model = db.get(Model, id) db.refresh(model) return ModelModel.model_validate(model) except Exception as e: