Browse Source

fix: model update

Timothy J. Baek 10 months ago
parent
commit
42742d03d7
1 changed files with 7 additions and 3 deletions
  1. 7 3
      backend/apps/webui/models/models.py

+ 7 - 3
backend/apps/webui/models/models.py

@@ -159,11 +159,15 @@ class ModelsTable:
     def update_model_by_id(self, id: str, model: ModelForm) -> Optional[ModelModel]:
     def update_model_by_id(self, id: str, model: ModelForm) -> Optional[ModelModel]:
         try:
         try:
             with get_db() as db:
             with get_db() as db:
-
                 # update only the fields that are present in the model
                 # 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()
                 db.commit()
+
+                model = db.get(Model, id)
                 db.refresh(model)
                 db.refresh(model)
                 return ModelModel.model_validate(model)
                 return ModelModel.model_validate(model)
         except Exception as e:
         except Exception as e: