fix: model update

This commit is contained in:
Timothy J. Baek 2024-07-08 11:58:36 -07:00
parent 87f656b029
commit 42742d03d7

View File

@ -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) result = (
model.update(**model.model_dump()) 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: