Skip to content

Commit

Permalink
Update sqlalchemy.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cobycloud authored Nov 20, 2024
1 parent 3b21e77 commit ba2dc08
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkgs/crouton/crouton/core/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@ def route(
try:
db_model: Model = self._get_one()(item_id, db)

for key, value in model.dict(exclude={self._pk}).items():
# Use exclude_unset=True to only update provided fields
update_data = model.dict(exclude={self._pk}, exclude_unset=True)

for key, value in update_data.items():
if hasattr(db_model, key):
setattr(db_model, key, value)

db.commit()
db.refresh(db_model)

return db_model
except IntegrityError as e:
db.rollback()
Expand Down

0 comments on commit ba2dc08

Please sign in to comment.