Commit 42742d03 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

fix: model update

parent 87f656b0
...@@ -159,11 +159,15 @@ class ModelsTable: ...@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment